Development Setup
This guide will help you set up a local development environment for contributing to Nitro GraphQL.
Prerequisites
Before you begin, ensure you have the following installed:
- Node.js: v18.0.0 or higher
- pnpm: v10.18.0 or higher (specified in package.json)
- Git: Latest version
Initial Setup
1. Fork and Clone
First, fork the repository on GitHub, then clone your fork:
git clone https://github.com/YOUR_USERNAME/nitro-graphql.git
cd nitro-graphql2. Enable Corepack
Corepack ensures you use the correct package manager version:
corepack enable3. Install Dependencies
Install all project dependencies using pnpm:
pnpm install --frozen-lockfileThis will install dependencies for:
- The main module
- All playground environments
- Documentation site
Development Workflow
Building the Module
The project uses tsdown as its build tool. There are two main build modes:
Production Build
Build the module once:
pnpm buildOutput will be generated in the dist/ directory.
Watch Mode (Development)
Keep the module building automatically as you make changes:
pnpm devThis is the recommended mode for active development. Keep this running in a dedicated terminal window.
Testing with Playgrounds
Nitro GraphQL includes multiple playground environments for testing different scenarios. You'll typically need two terminal windows:
Terminal 1: Run the build watcher
pnpm devTerminal 2: Run a playground
Nitro Playground (Standalone Server)
Test the module in a standalone Nitro application:
pnpm playground:nitroThis starts a Nitro server with GraphQL at http://localhost:3000/api/graphql.
Manual approach (if you need more control):
cd playgrounds/nitro
pnpm install
pnpm devNuxt Playground (Full-Stack)
Test the module in a full Nuxt application with client-side features:
pnpm playground:nuxtThis starts a Nuxt app at http://localhost:3000 with:
- Server GraphQL API
- Client-side type generation
- Frontend components using GraphQL
Manual approach:
cd playgrounds/nuxt
pnpm install
pnpm devFederation Playground
Test Apollo Federation features with multiple subgraphs:
pnpm playground:federationThis starts multiple services demonstrating federated GraphQL architecture.
Manual approach:
cd playgrounds/federation
pnpm install
pnpm devOther Available Playgrounds
The project includes additional playground environments:
playgrounds/apollo- Apollo Server integrationplaygrounds/vite- Vite integration testing
Navigate to the specific directory and run pnpm dev to start them.
Code Quality
Linting
Check code quality and style:
pnpm lintAutomatically fix linting issues:
pnpm lint:fixThe project uses @antfu/eslint-config for consistent code style.
Type Checking
TypeScript type checking is handled automatically during the build process. Run:
pnpm buildWatch for type errors in the console output.
Development Commands Reference
Here's a complete reference of available commands:
| Command | Description |
|---|---|
pnpm install | Install all dependencies |
pnpm build | Build the module for production |
pnpm dev | Build in watch mode for development |
pnpm lint | Check code quality with ESLint |
pnpm lint:fix | Auto-fix linting issues |
pnpm playground:nitro | Run Nitro playground |
pnpm playground:nuxt | Run Nuxt playground |
pnpm playground:federation | Run Federation playground |
pnpm bumpp | Bump version (maintainers only) |
pnpm release | Build and publish (maintainers only) |
Project Structure
Understanding the project structure will help you navigate the codebase:
nitro-graphql/
├── src/ # Source code
│ ├── index.ts # Main module entry
│ ├── rollup.ts # Rollup plugin
│ ├── routes/ # Runtime route handlers
│ │ ├── graphql-yoga.ts # GraphQL Yoga server
│ │ ├── apollo-server.ts # Apollo Server handler
│ │ └── health.ts # Health check endpoint
│ ├── utils/ # Utility functions
│ │ ├── index.ts # File scanning (schemas, resolvers)
│ │ ├── define.ts # Resolver definition utilities
│ │ ├── type-generation.ts # Type generation orchestration
│ │ ├── server-codegen.ts # Server type generation
│ │ ├── client-codegen.ts # Client type generation
│ │ ├── path-resolver.ts # Path resolution (v2.0+)
│ │ ├── file-generator.ts # File generation (v2.0+)
│ │ ├── apollo.ts # Apollo utilities
│ │ └── directive-parser.ts # Directive parsing
│ ├── types/ # TypeScript type definitions
│ ├── virtual/ # Virtual module implementations
│ ├── graphql/ # GraphQL runtime exports
│ └── ecosystem/ # Framework integrations
│ └── nuxt.ts # Nuxt module integration
├── playgrounds/ # Test environments
│ ├── nitro/ # Nitro playground
│ ├── nuxt/ # Nuxt playground
│ ├── federation/ # Federation playground
│ ├── apollo/ # Apollo Server playground
│ └── vite/ # Vite playground
├── dist/ # Build output (generated)
├── .docs/ # Documentation site (VitePress)
├── tsdown.config.ts # Build configuration
├── package.json # Package configuration
└── pnpm-workspace.yaml # pnpm workspace configurationDebugging Tips
Debugging Type Generation
When working on type generation features:
Check generated files in playground directories:
- Nitro:
.nitro/types/nitro-graphql-{server,client}.d.ts - Nuxt:
.nuxt/types/nitro-graphql-{server,client}.d.ts
- Nitro:
Enable verbose logging (if implemented) in your test configuration
Check the generated schema file:
server/graphql/schema.ts(auto-generated)
Debugging File Discovery
To debug schema and resolver discovery:
- Add console logs in
src/utils/index.ts - Check the
scanSchemas()andscanResolvers()functions - Verify files match the expected patterns:
- Schemas:
**/*.graphql - Resolvers:
**/*.resolver.ts
- Schemas:
Debugging Build Issues
If the build fails or produces unexpected output:
Clean the dist directory:
bashrm -rf dist pnpm buildCheck for TypeScript errors in the console
Verify
tsdown.config.tsconfigurationCheck that external dependencies are properly declared
Common Issues
Module Not Found in Playground
If the playground can't find the module:
# From the root directory
pnpm build
# Then reinstall playground dependencies
cd playgrounds/nitro
rm -rf node_modules
pnpm installTypes Not Updating
If generated types aren't updating:
- Restart the dev server in the playground
- Delete the build directory (
.nitroor.nuxt) - Ensure
pnpm devis running in the root directory
pnpm Version Mismatch
If you see pnpm version errors:
corepack enable
corepack prepare pnpm@10.18.0 --activateNext Steps
Now that you have your development environment set up:
- Read the Architecture guide to understand the codebase
- Learn about Adding Features
- Check the Documentation guide for writing docs
Getting Help
If you encounter issues during setup:
- Check existing GitHub Issues
- Open a new issue with details about your setup
- Ask in GitHub Discussions