nitro-graphql 2.0.0-beta.4 → 2.0.0-beta.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +441 -27
  2. package/dist/cli/commands/generate.d.mts +26 -0
  3. package/dist/cli/commands/generate.mjs +196 -0
  4. package/dist/cli/commands/index.d.mts +4 -0
  5. package/dist/cli/commands/index.mjs +5 -0
  6. package/dist/cli/commands/init.d.mts +46 -0
  7. package/dist/cli/commands/init.mjs +195 -0
  8. package/dist/cli/commands/validate.d.mts +10 -0
  9. package/dist/cli/commands/validate.mjs +69 -0
  10. package/dist/cli/completions.d.mts +7 -0
  11. package/dist/cli/completions.mjs +34 -0
  12. package/dist/cli/config.d.mts +75 -0
  13. package/dist/cli/config.mjs +20 -0
  14. package/dist/cli/index.d.mts +24 -0
  15. package/dist/cli/index.mjs +253 -0
  16. package/dist/core/codegen/client.d.mts +23 -0
  17. package/dist/core/codegen/client.mjs +150 -0
  18. package/dist/core/codegen/document-loader.d.mts +10 -0
  19. package/dist/core/codegen/document-loader.mjs +18 -0
  20. package/dist/core/codegen/index.d.mts +8 -0
  21. package/dist/core/codegen/index.mjs +9 -0
  22. package/dist/core/codegen/plugin.d.mts +20 -0
  23. package/dist/core/codegen/plugin.mjs +30 -0
  24. package/dist/core/codegen/runtime.d.mts +20 -0
  25. package/dist/core/codegen/runtime.mjs +60 -0
  26. package/dist/core/codegen/schema-loader.d.mts +28 -0
  27. package/dist/core/codegen/schema-loader.mjs +128 -0
  28. package/dist/core/codegen/server.d.mts +28 -0
  29. package/dist/core/codegen/server.mjs +143 -0
  30. package/dist/core/codegen/validation.d.mts +13 -0
  31. package/dist/core/codegen/validation.mjs +96 -0
  32. package/dist/core/config.d.mts +50 -0
  33. package/dist/core/config.mjs +82 -0
  34. package/dist/core/constants.d.mts +188 -0
  35. package/dist/core/constants.mjs +210 -0
  36. package/dist/core/index.d.mts +32 -0
  37. package/dist/core/index.mjs +26 -0
  38. package/dist/core/scanning/ast-scanner.d.mts +23 -0
  39. package/dist/core/scanning/ast-scanner.mjs +103 -0
  40. package/dist/core/scanning/common.d.mts +37 -0
  41. package/dist/core/scanning/common.mjs +60 -0
  42. package/dist/core/scanning/directives.d.mts +10 -0
  43. package/dist/core/scanning/directives.mjs +29 -0
  44. package/dist/core/scanning/documents.d.mts +21 -0
  45. package/dist/core/scanning/documents.mjs +43 -0
  46. package/dist/core/scanning/index.d.mts +7 -0
  47. package/dist/core/scanning/index.mjs +8 -0
  48. package/dist/core/scanning/resolvers.d.mts +10 -0
  49. package/dist/core/scanning/resolvers.mjs +58 -0
  50. package/dist/core/scanning/schemas.d.mts +14 -0
  51. package/dist/core/scanning/schemas.mjs +64 -0
  52. package/dist/core/schema/builder.d.mts +53 -0
  53. package/dist/core/schema/builder.mjs +70 -0
  54. package/dist/core/schema/federation.d.mts +34 -0
  55. package/dist/core/schema/federation.mjs +40 -0
  56. package/dist/core/schema/index.d.mts +3 -0
  57. package/dist/core/schema/index.mjs +4 -0
  58. package/dist/core/types/adapter.d.mts +58 -0
  59. package/dist/core/types/codegen.d.mts +133 -0
  60. package/dist/core/types/config.d.mts +212 -0
  61. package/dist/core/types/config.mjs +1 -0
  62. package/dist/{utils/define.d.ts → core/types/define.d.mts} +3 -30
  63. package/dist/core/types/define.mjs +1 -0
  64. package/dist/core/types/index.d.mts +5 -0
  65. package/dist/core/types/index.mjs +1 -0
  66. package/dist/core/types/scanning.d.mts +69 -0
  67. package/dist/core/types/scanning.mjs +1 -0
  68. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +21 -4
  69. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +25 -34
  70. package/dist/core/utils/errors.d.mts +77 -0
  71. package/dist/core/utils/errors.mjs +93 -0
  72. package/dist/core/utils/file-io.d.mts +24 -0
  73. package/dist/core/utils/file-io.mjs +47 -0
  74. package/dist/core/utils/imports.d.mts +15 -0
  75. package/dist/core/utils/imports.mjs +25 -0
  76. package/dist/core/utils/index.d.mts +7 -0
  77. package/dist/core/utils/index.mjs +8 -0
  78. package/dist/core/utils/logger.d.mts +19 -0
  79. package/dist/core/utils/logger.mjs +38 -0
  80. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  81. package/dist/core/utils/ofetch-templates.mjs +135 -0
  82. package/dist/core/validation/external-services.d.mts +11 -0
  83. package/dist/core/validation/external-services.mjs +34 -0
  84. package/dist/core/validation/index.d.mts +2 -0
  85. package/dist/core/validation/index.mjs +3 -0
  86. package/dist/define.d.mts +294 -0
  87. package/dist/define.mjs +323 -0
  88. package/dist/index.d.mts +6 -0
  89. package/dist/index.mjs +6 -0
  90. package/dist/nitro/adapter.d.mts +30 -0
  91. package/dist/nitro/adapter.mjs +97 -0
  92. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  93. package/dist/nitro/apollo.mjs +59 -0
  94. package/dist/nitro/codegen.d.mts +19 -0
  95. package/dist/nitro/codegen.mjs +141 -0
  96. package/dist/nitro/config.d.mts +52 -0
  97. package/dist/nitro/config.mjs +58 -0
  98. package/dist/nitro/index.d.mts +46 -0
  99. package/dist/nitro/index.mjs +65 -0
  100. package/dist/nitro/paths.d.mts +54 -0
  101. package/dist/nitro/paths.mjs +93 -0
  102. package/dist/nitro/rollup.d.mts +6 -0
  103. package/dist/nitro/rollup.mjs +95 -0
  104. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  105. package/dist/nitro/routes/apollo-server.mjs +71 -0
  106. package/dist/nitro/routes/debug-template.d.mts +15 -0
  107. package/dist/nitro/routes/debug-template.mjs +385 -0
  108. package/dist/nitro/routes/debug.d.mts +55 -0
  109. package/dist/nitro/routes/debug.mjs +102 -0
  110. package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
  111. package/dist/nitro/routes/graphql-yoga.mjs +62 -0
  112. package/dist/nitro/routes/health.d.mts +10 -0
  113. package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
  114. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  115. package/dist/nitro/setup/file-watcher.mjs +80 -0
  116. package/dist/nitro/setup/logging.d.mts +17 -0
  117. package/dist/nitro/setup/logging.mjs +66 -0
  118. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  119. package/dist/nitro/setup/rollup-integration.mjs +90 -0
  120. package/dist/nitro/setup/routes.d.mts +10 -0
  121. package/dist/nitro/setup/routes.mjs +35 -0
  122. package/dist/nitro/setup/ts-config.d.mts +11 -0
  123. package/dist/nitro/setup/ts-config.mjs +69 -0
  124. package/dist/nitro/setup.d.mts +12 -0
  125. package/dist/nitro/setup.mjs +231 -0
  126. package/dist/nitro/types.d.mts +378 -0
  127. package/dist/nitro/types.mjs +1 -0
  128. package/dist/nitro/virtual/generators.d.mts +31 -0
  129. package/dist/nitro/virtual/generators.mjs +193 -0
  130. package/dist/nitro/virtual/stubs.d.mts +20 -0
  131. package/dist/nitro/virtual/stubs.mjs +31 -0
  132. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  133. package/dist/nuxt.mjs +109 -0
  134. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  135. package/dist/stubs/index.mjs +1 -0
  136. package/package.json +97 -78
  137. package/dist/ecosystem/nuxt.js +0 -67
  138. package/dist/graphql/index.d.ts +0 -5
  139. package/dist/index.d.ts +0 -8
  140. package/dist/index.js +0 -264
  141. package/dist/rollup.js +0 -119
  142. package/dist/routes/apollo-server.d.ts +0 -6
  143. package/dist/routes/apollo-server.js +0 -89
  144. package/dist/routes/graphql-yoga.d.ts +0 -6
  145. package/dist/routes/graphql-yoga.js +0 -91
  146. package/dist/routes/health.d.ts +0 -6
  147. package/dist/types/index.d.ts +0 -128
  148. package/dist/types/standard-schema.d.ts +0 -59
  149. package/dist/utils/apollo.js +0 -61
  150. package/dist/utils/client-codegen.d.ts +0 -38
  151. package/dist/utils/client-codegen.js +0 -290
  152. package/dist/utils/define.js +0 -57
  153. package/dist/utils/index.d.ts +0 -39
  154. package/dist/utils/index.js +0 -250
  155. package/dist/utils/server-codegen.d.ts +0 -7
  156. package/dist/utils/server-codegen.js +0 -136
  157. package/dist/utils/type-generation.d.ts +0 -7
  158. package/dist/utils/type-generation.js +0 -287
  159. package/dist/vite.d.ts +0 -25
  160. package/dist/vite.js +0 -40
  161. /package/dist/{graphql/index.js → core/types/adapter.mjs} +0 -0
  162. /package/dist/{graphql/server.js → core/types/codegen.mjs} +0 -0
package/README.md CHANGED
@@ -1,20 +1,31 @@
1
- # Nitro GraphQL
2
-
3
1
  <div align="center">
4
2
 
3
+ <img src="./.github/assets/logo.svg" alt="Nitro GraphQL Logo" width="120" height="120">
4
+
5
+ # Nitro GraphQL
6
+
5
7
  [![npm version][npm-version-src]][npm-version-href]
8
+ [![Beta Status][beta-src]][beta-href]
6
9
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
7
10
  [![bundle][bundle-src]][bundle-href]
8
11
  [![License][license-src]][license-href]
12
+ [![Documentation][docs-src]][docs-href]
9
13
 
10
14
  **The easiest way to add GraphQL to any Nitro application**
11
15
 
12
16
  🚀 **Auto-discovery** • 📝 **Type Generation** • 🎮 **Apollo Sandbox** • 🔧 **Zero Config**
13
17
 
14
- [Quick Start](#-quick-start) • [Examples](#-examples) • [Documentation](#-documentation) • [Community](#-community)
18
+ [📚 Documentation](https://nitro-graphql.pages.dev) • [Quick Start](#-quick-start) • [Examples](#-examples) • [Community](#-community)
15
19
 
16
20
  </div>
17
21
 
22
+ > [!IMPORTANT]
23
+ > **v2.0 Beta (Current - Main Branch)**
24
+ > This is the **v2.0** beta branch with Nitro v3 and H3 v2 support. Includes Rolldown optimization, improved chunking, and enhanced Vite integration.
25
+ >
26
+ > **Looking for v1.x?**
27
+ > For the stable v1 version (Nitro v2), see the [`v1` branch](https://github.com/productdevbook/nitro-graphql/tree/v1).
28
+
18
29
  ---
19
30
 
20
31
  ## 🎥 Watch & Learn
@@ -31,18 +42,26 @@
31
42
  - 🎮 **Developer-friendly** - Built-in Apollo Sandbox for testing
32
43
  - 🔧 **Zero config** - Sensible defaults, customize when needed
33
44
 
45
+ ### 🆕 What's New in v2.0 Beta
46
+
47
+ - 🚀 **Nitro v3 & H3 v2** - Full compatibility with the latest Nitro and H3
48
+ - ⚙️ **Rolldown Support** - Optimized for both Rolldown (Vite 7+) and Rollup
49
+ - 📦 **Smart Chunking** - GraphQL code split into separate chunks (~98% size reduction)
50
+ - 🔍 **Debug Dashboard** - Built-in diagnostics at `/_nitro/graphql/debug` (dev only)
51
+ - 🎨 **Enhanced Vite Integration** - Better custom path support and virtual module resolution
52
+
34
53
  ## 🚀 Quick Start
35
54
 
36
55
  ### 1. Install
37
56
 
38
57
  **GraphQL Yoga (recommended):**
39
58
  ```bash
40
- pnpm add nitro-graphql graphql-yoga graphql
59
+ pnpm add nitro-graphql@beta graphql-yoga graphql graphql-config
41
60
  ```
42
61
 
43
62
  **Apollo Server:**
44
63
  ```bash
45
- pnpm add nitro-graphql @apollo/server @apollo/utils.withrequired @as-integrations/h3 graphql
64
+ pnpm add nitro-graphql@beta @apollo/server graphql graphql-config
46
65
  ```
47
66
 
48
67
  ### 2. Configure
@@ -52,13 +71,15 @@ pnpm add nitro-graphql @apollo/server @apollo/utils.withrequired @as-integration
52
71
 
53
72
  ```ts
54
73
  // nitro.config.ts
74
+ import graphql from 'nitro-graphql'
55
75
  import { defineNitroConfig } from 'nitro/config'
56
76
 
57
77
  export default defineNitroConfig({
58
- modules: ['nitro-graphql'],
59
- graphql: {
60
- framework: 'graphql-yoga', // or 'apollo-server'
61
- },
78
+ modules: [
79
+ graphql({
80
+ framework: 'graphql-yoga', // or 'apollo-server'
81
+ }),
82
+ ],
62
83
  })
63
84
  ```
64
85
 
@@ -71,18 +92,20 @@ export default defineNitroConfig({
71
92
  // vite.config.ts
72
93
  import { defineConfig } from 'vite'
73
94
  import { nitro } from 'nitro/vite'
74
- import { graphql } from 'nitro-graphql/vite'
95
+ import graphql from 'nitro-graphql'
96
+ import { graphql as graphqlVite } from 'nitro-graphql/vite'
75
97
 
76
98
  export default defineConfig({
77
99
  plugins: [
78
- graphql(), // ⚠️ Must be before nitro()
100
+ graphqlVite(), // ⚠️ Must be before nitro()
79
101
  nitro(),
80
102
  ],
81
103
  nitro: {
82
- modules: ['nitro-graphql'],
83
- graphql: {
84
- framework: 'graphql-yoga',
85
- },
104
+ modules: [
105
+ graphql({
106
+ framework: 'graphql-yoga',
107
+ }),
108
+ ],
86
109
  },
87
110
  })
88
111
  ```
@@ -126,6 +149,8 @@ type Mutation {
126
149
 
127
150
  ```ts
128
151
  // server/graphql/hello.resolver.ts
152
+ import { defineResolver } from 'nitro-graphql/define'
153
+
129
154
  export const helloResolver = defineResolver({
130
155
  Query: {
131
156
  hello: () => 'Hello from GraphQL!',
@@ -144,6 +169,7 @@ pnpm dev
144
169
  - **Endpoint**: `http://localhost:3000/api/graphql`
145
170
  - **Playground**: `http://localhost:3000/api/graphql` (browser)
146
171
  - **Health**: `http://localhost:3000/api/graphql/health`
172
+ - **Debug Dashboard**: `http://localhost:3000/_nitro/graphql/debug` (dev mode only)
147
173
 
148
174
  ## 🎮 Examples
149
175
 
@@ -155,6 +181,14 @@ Try these working examples:
155
181
  | [**Vite + Nitro**](./playgrounds/vite/) | Vite with Nitro GraphQL integration | `cd playgrounds/vite && pnpm dev` |
156
182
  | [**Nuxt Integration**](./playgrounds/nuxt/) | Full Nuxt app with client types | `pnpm playground:nuxt` |
157
183
  | [**Apollo Federation**](./playgrounds/federation/) | Federated GraphQL services | `pnpm playground:federation` |
184
+ | [**Drizzle ORM**](./examples/drizzle-orm/) | Drizzle ORM + Zod validation integration | `cd examples/drizzle-orm && pnpm dev` |
185
+
186
+ ### 🧪 Test Projects
187
+
188
+ Real-world test projects using nitro-graphql v2:
189
+
190
+ - [**Vite + Nitro + Rolldown**](https://github.com/productdevbook/vite-nitro-graphql/tree/rolldown) - Testing with Rolldown bundler (Vite 7+)
191
+ - [**Vite + Nitro (Main)**](https://github.com/productdevbook/vite-nitro-graphql) - Standard Vite integration tests
158
192
 
159
193
  ## 🏗️ Building Your First Feature
160
194
 
@@ -188,6 +222,8 @@ extend type Mutation {
188
222
  ### 2. Create Resolvers
189
223
  ```ts
190
224
  // server/graphql/users/user.resolver.ts
225
+ import { defineQuery, defineMutation } from 'nitro-graphql/define'
226
+
191
227
  export const userQueries = defineQuery({
192
228
  users: async (_, __, { storage }) => {
193
229
  return await storage.getItem('users') || []
@@ -238,6 +274,261 @@ query {
238
274
 
239
275
  ## 🚀 Advanced Features
240
276
 
277
+ <details>
278
+ <summary><strong>🎛️ Custom File Generation & Paths</strong></summary>
279
+
280
+ Control which files are auto-generated and customize their output paths. Perfect for library development, monorepos, or custom project structures.
281
+
282
+ ### Library Mode
283
+
284
+ Disable all scaffold files for library/module development:
285
+
286
+ ```ts
287
+ // nitro.config.ts
288
+ import graphql from 'nitro-graphql'
289
+ import { defineNitroConfig } from 'nitro/config'
290
+
291
+ export default defineNitroConfig({
292
+ modules: [
293
+ graphql({
294
+ framework: 'graphql-yoga',
295
+ scaffold: false, // Disable all scaffold files
296
+ clientUtils: false, // Disable client utilities
297
+ }),
298
+ ],
299
+ })
300
+ ```
301
+
302
+ ### Fine-Grained Control
303
+
304
+ Control each file individually:
305
+
306
+ ```ts
307
+ import graphql from 'nitro-graphql'
308
+ import { defineNitroConfig } from 'nitro/config'
309
+
310
+ export default defineNitroConfig({
311
+ modules: [
312
+ graphql({
313
+ framework: 'graphql-yoga',
314
+
315
+ // Scaffold files
316
+ scaffold: {
317
+ graphqlConfig: false, // Don't generate graphql.config.ts
318
+ serverSchema: true, // Generate server/graphql/schema.ts
319
+ serverConfig: true, // Generate server/graphql/config.ts
320
+ serverContext: false, // Don't generate server/graphql/context.ts
321
+ },
322
+
323
+ // Client utilities (Nuxt only)
324
+ clientUtils: {
325
+ index: true, // Generate app/graphql/index.ts
326
+ ofetch: false, // Don't generate ofetch wrappers
327
+ },
328
+
329
+ // SDK files
330
+ sdk: {
331
+ main: true, // Generate default SDK
332
+ external: true, // Generate external service SDKs
333
+ },
334
+
335
+ // Type files
336
+ types: {
337
+ server: true, // Generate server types
338
+ client: true, // Generate client types
339
+ external: true, // Generate external service types
340
+ },
341
+ }),
342
+ ],
343
+ })
344
+ ```
345
+
346
+ ### Custom Paths
347
+
348
+ Customize where files are generated:
349
+
350
+ ```ts
351
+ import graphql from 'nitro-graphql'
352
+ import { defineNitroConfig } from 'nitro/config'
353
+
354
+ export default defineNitroConfig({
355
+ modules: [
356
+ graphql({
357
+ framework: 'graphql-yoga',
358
+
359
+ // Method 1: Global paths (affects all files)
360
+ paths: {
361
+ serverGraphql: 'src/server/graphql',
362
+ clientGraphql: 'src/client/graphql',
363
+ buildDir: '.build',
364
+ typesDir: '.build/types',
365
+ },
366
+
367
+ // Method 2: Specific file paths
368
+ scaffold: {
369
+ serverSchema: 'lib/graphql/schema.ts',
370
+ serverConfig: 'lib/graphql/config.ts',
371
+ },
372
+
373
+ sdk: {
374
+ main: 'app/graphql/organization/sdk.ts',
375
+ external: 'app/graphql/{serviceName}/client-sdk.ts',
376
+ },
377
+
378
+ types: {
379
+ server: 'types/graphql-server.d.ts',
380
+ client: 'types/graphql-client.d.ts',
381
+ },
382
+ }),
383
+ ],
384
+ })
385
+ ```
386
+
387
+ ### Path Placeholders
388
+
389
+ Use placeholders in custom paths:
390
+
391
+ | Placeholder | Description | Example |
392
+ |------------|-------------|---------|
393
+ | `{serviceName}` | External service name | `github`, `stripe` |
394
+ | `{buildDir}` | Build directory | `.nitro` or `.nuxt` |
395
+ | `{rootDir}` | Root directory | `/Users/you/project` |
396
+ | `{framework}` | Framework name | `nuxt` or `nitro` |
397
+ | `{typesDir}` | Types directory | `.nitro/types` |
398
+ | `{serverGraphql}` | Server GraphQL dir | `server/graphql` |
399
+ | `{clientGraphql}` | Client GraphQL dir | `app/graphql` |
400
+
401
+ Example:
402
+ ```ts
403
+ sdk: {
404
+ external: '{clientGraphql}/{serviceName}/sdk.ts'
405
+ }
406
+ // → app/graphql/github/sdk.ts
407
+ // → app/graphql/stripe/sdk.ts
408
+ ```
409
+
410
+ ### Service-Specific Paths
411
+
412
+ Customize paths for individual external services:
413
+
414
+ ```ts
415
+ export default defineNuxtConfig({
416
+ nitro: {
417
+ graphql: {
418
+ framework: 'graphql-yoga',
419
+
420
+ // Global default for all external services
421
+ sdk: {
422
+ external: 'app/graphql/{serviceName}/sdk.ts'
423
+ },
424
+
425
+ externalServices: [
426
+ {
427
+ name: 'github',
428
+ endpoint: 'https://api.github.com/graphql',
429
+ schema: 'https://api.github.com/graphql',
430
+
431
+ // GitHub-specific paths (override global config)
432
+ paths: {
433
+ sdk: 'app/graphql/organization/github-sdk.ts',
434
+ types: 'types/github.d.ts',
435
+ ofetch: 'app/graphql/organization/github-client.ts'
436
+ }
437
+ },
438
+ {
439
+ name: 'stripe',
440
+ endpoint: 'https://api.stripe.com/graphql',
441
+ schema: 'https://api.stripe.com/graphql',
442
+
443
+ // Stripe-specific paths
444
+ paths: {
445
+ sdk: 'app/graphql/payments/stripe-sdk.ts',
446
+ types: 'types/payments/stripe.d.ts',
447
+ // ofetch uses global config
448
+ }
449
+ },
450
+ {
451
+ name: 'shopify',
452
+ endpoint: 'https://api.shopify.com/graphql',
453
+ // No paths → uses global config
454
+ // → app/graphql/shopify/sdk.ts
455
+ }
456
+ ]
457
+ }
458
+ }
459
+ })
460
+ ```
461
+
462
+ ### Path Resolution Priority
463
+
464
+ When resolving file paths, the system follows this priority order:
465
+
466
+ 1. **Service-specific path** (for external services): `service.paths.sdk`
467
+ 2. **Category config**: `sdk.external` or `sdk.main`
468
+ 3. **Global paths**: `paths.clientGraphql`
469
+ 4. **Framework defaults**: Nuxt vs Nitro defaults
470
+
471
+ Example:
472
+ ```ts
473
+ // Given this config:
474
+ {
475
+ paths: { clientGraphql: 'custom/graphql' },
476
+ sdk: { external: '{clientGraphql}/{serviceName}/sdk.ts' },
477
+ externalServices: [
478
+ {
479
+ name: 'github',
480
+ paths: { sdk: 'app/org/github-sdk.ts' } // ← Wins (priority 1)
481
+ },
482
+ {
483
+ name: 'stripe',
484
+ // Uses sdk.external (priority 2)
485
+ // → custom/graphql/stripe/sdk.ts
486
+ }
487
+ ]
488
+ }
489
+ ```
490
+
491
+ ### Use Cases
492
+
493
+ **Monorepo structure:**
494
+ ```ts
495
+ paths: {
496
+ serverGraphql: 'packages/api/src/graphql',
497
+ clientGraphql: 'packages/web/src/graphql',
498
+ typesDir: 'packages/types/src/generated',
499
+ }
500
+ ```
501
+
502
+ **Multiple external service organizations:**
503
+ ```ts
504
+ externalServices: [
505
+ {
506
+ name: 'github',
507
+ paths: { sdk: 'app/graphql/vcs/github-sdk.ts' }
508
+ },
509
+ {
510
+ name: 'gitlab',
511
+ paths: { sdk: 'app/graphql/vcs/gitlab-sdk.ts' }
512
+ },
513
+ {
514
+ name: 'stripe',
515
+ paths: { sdk: 'app/graphql/billing/stripe-sdk.ts' }
516
+ }
517
+ ]
518
+ ```
519
+
520
+ **Library development (no scaffolding):**
521
+ ```ts
522
+ {
523
+ scaffold: false,
524
+ clientUtils: false,
525
+ sdk: { enabled: true }, // Only generate SDKs
526
+ types: { enabled: true }, // Only generate types
527
+ }
528
+ ```
529
+
530
+ </details>
531
+
241
532
  <details>
242
533
  <summary><strong>🎭 Custom Directives</strong></summary>
243
534
 
@@ -245,6 +536,8 @@ Create reusable GraphQL directives:
245
536
 
246
537
  ```ts
247
538
  // server/graphql/directives/auth.directive.ts
539
+ import { defineDirective } from 'nitro-graphql/define'
540
+
248
541
  export const authDirective = defineDirective({
249
542
  name: 'auth',
250
543
  locations: ['FIELD_DEFINITION'],
@@ -302,14 +595,19 @@ Build federated GraphQL services:
302
595
 
303
596
  ```ts
304
597
  // nitro.config.ts
598
+ import graphql from 'nitro-graphql'
599
+ import { defineNitroConfig } from 'nitro/config'
600
+
305
601
  export default defineNitroConfig({
306
- graphql: {
307
- framework: 'apollo-server',
308
- federation: {
309
- enabled: true,
310
- serviceName: 'users-service'
311
- }
312
- }
602
+ modules: [
603
+ graphql({
604
+ framework: 'apollo-server',
605
+ federation: {
606
+ enabled: true,
607
+ serviceName: 'users-service',
608
+ },
609
+ }),
610
+ ],
313
611
  })
314
612
  ```
315
613
 
@@ -319,15 +617,24 @@ export default defineNitroConfig({
319
617
 
320
618
  ### Core Utilities
321
619
 
322
- All utilities are auto-imported in resolver files:
620
+ > **⚠️ Breaking Change**: Utilities are **NOT auto-imported**. You must explicitly import them from `nitro-graphql/define`:
621
+
622
+ ```typescript
623
+ import { defineResolver, defineQuery, defineMutation, defineField, defineDirective } from 'nitro-graphql/define'
624
+ ```
323
625
 
324
626
  | Function | Purpose | Example |
325
627
  |----------|---------|---------|
326
628
  | `defineResolver` | Complete resolvers | `defineResolver({ Query: {...}, Mutation: {...} })` |
327
629
  | `defineQuery` | Query-only resolvers | `defineQuery({ users: () => [...] })` |
328
630
  | `defineMutation` | Mutation-only resolvers | `defineMutation({ createUser: (...) => {...} })` |
329
- | `defineType` | Custom type resolvers | `defineType({ User: { posts: (parent) => [...] } })` |
631
+ | `defineField` | Custom type resolvers | `defineField({ User: { posts: (parent) => [...] } })` |
330
632
  | `defineDirective` | Custom directives | `defineDirective({ name: 'auth', ... })` |
633
+ | `defineGraphQLConfig` | GraphQL server config | `defineGraphQLConfig({ maskedErrors: {...} })` |
634
+ | `defineSchema` | Schema with Zod integration | `defineSchema({ Book: selectBookSchema })` |
635
+
636
+ **Additional Utilities** from `nitro-graphql/core`:
637
+ - `createDefaultMaskError()` - Error handler for ZodError and HTTPError (use in `defineGraphQLConfig`)
331
638
 
332
639
  ### Type Generation
333
640
 
@@ -381,10 +688,19 @@ server/
381
688
  - ✅ Check file naming: `*.graphql`, `*.resolver.ts`
382
689
  - ✅ Verify exports are named exports
383
690
 
384
- **Import errors**
385
- - ✅ Use correct path: `nitro-graphql/utils/define`
691
+ **Import errors / "defineQuery is not defined"**
692
+ - ✅ **Requires explicit imports**: Add `import { defineQuery } from 'nitro-graphql/define'` to resolver files
693
+ - ✅ Use correct import path: `nitro-graphql/define` (not `nitro-graphql`)
386
694
  - ✅ Use named exports in resolvers
387
695
 
696
+ Example fix:
697
+ ```typescript
698
+ // Add this to the top of your resolver file
699
+ import { defineQuery, defineMutation } from 'nitro-graphql/define'
700
+
701
+ export const myQueries = defineQuery({ ... })
702
+ ```
703
+
388
704
  **Vite: "Parse failure: Expected ';', '}' or <eof>" on GraphQL files**
389
705
  - ✅ Add `graphql()` plugin from `nitro-graphql/vite`
390
706
  - ✅ Ensure `graphql()` is placed **before** `nitro()` in plugins array
@@ -400,6 +716,79 @@ server/
400
716
  })
401
717
  ```
402
718
 
719
+ **RollupError: "[exportName]" is not exported by "[file].resolver.ts"**
720
+
721
+ This error occurs when the resolver scanner can't find the expected export in your resolver file. Common causes:
722
+
723
+ 1. **Using default export instead of named export** ❌
724
+ ```ts
725
+ // ❌ WRONG - Will not be detected
726
+ export default defineQuery({
727
+ users: () => [...]
728
+ })
729
+ ```
730
+
731
+ ```ts
732
+ // ✅ CORRECT - Use named export
733
+ export const userQueries = defineQuery({
734
+ users: () => [...]
735
+ })
736
+ ```
737
+
738
+ 2. **Not using a define function** ❌
739
+ ```ts
740
+ // ❌ WRONG - Plain object won't be detected
741
+ export const resolvers = {
742
+ Query: {
743
+ users: () => [...]
744
+ }
745
+ }
746
+ ```
747
+
748
+ ```ts
749
+ // ✅ CORRECT - Use defineResolver, defineQuery, etc.
750
+ export const userResolver = defineResolver({
751
+ Query: {
752
+ users: () => [...]
753
+ }
754
+ })
755
+ ```
756
+
757
+ 3. **File naming doesn't match export** ❌
758
+ ```ts
759
+ // ❌ File: uploadFile.resolver.ts but export is named differently
760
+ export const fileUploader = defineMutation({...})
761
+ ```
762
+
763
+ ```ts
764
+ // ✅ CORRECT - Export name can be anything, as long as it uses a define function
765
+ export const uploadFile = defineMutation({...})
766
+ export const fileUploader = defineMutation({...}) // Both work!
767
+ ```
768
+
769
+ 4. **Syntax errors preventing parsing**
770
+ - Check for TypeScript compilation errors in the file
771
+ - Ensure imports are valid
772
+ - Verify no missing brackets or syntax issues
773
+
774
+ **How resolver scanning works:**
775
+ - The module uses `oxc-parser` to scan `.resolver.ts` files
776
+ - It looks for **named exports** using these functions:
777
+ - `defineResolver` - Complete resolver with Query, Mutation, etc.
778
+ - `defineQuery` - Query-only resolvers
779
+ - `defineMutation` - Mutation-only resolvers
780
+ - `defineField` - Custom type resolvers
781
+ - `defineSubscription` - Subscription resolvers
782
+ - `defineDirective` - Directive resolvers
783
+ - Only exports using these functions are included in the virtual module
784
+
785
+ **Debugging steps:**
786
+ 1. Check your resolver file uses named exports: `export const name = defineQuery({...})`
787
+ 2. Verify you're using one of the define functions listed above
788
+ 3. Look for TypeScript/syntax errors in the file
789
+ 4. Restart the dev server after fixing
790
+ 5. If issues persist, simplify the resolver to test (single query)
791
+
403
792
  </details>
404
793
 
405
794
  ## 🌟 Production Usage
@@ -408,6 +797,27 @@ This package powers production applications:
408
797
 
409
798
  - [**Nitroping**](https://github.com/productdevbook/nitroping) - Self-hosted push notification service
410
799
 
800
+ ### Working with Your GraphQL API
801
+
802
+ Once set up, you can ask Claude Code for help with:
803
+
804
+ ```
805
+ "Add authentication to my GraphQL resolvers"
806
+ "Create a custom @auth directive for field-level permissions"
807
+ "Set up type generation for client-side queries"
808
+ "Add pagination to my users query"
809
+ "Connect to an external GitHub GraphQL API"
810
+ "Debug: my types aren't generating in .nitro/types/"
811
+ "Optimize resolver performance using DataLoader"
812
+ ```
813
+
814
+ ### Tips for Better Results
815
+
816
+ - **Start specific**: Include your framework (Nuxt/Nitro), version, and goal
817
+ - **Reference docs**: Mention "following nitro-graphql conventions" to align with best practices
818
+ - **Show errors**: Paste error messages for faster debugging
819
+ - **Test iteratively**: Run `pnpm dev` after each change to verify
820
+
411
821
  ## 🛠️ Development
412
822
 
413
823
  ```bash
@@ -467,4 +877,8 @@ pnpm lint
467
877
  [bundle-src]: https://deno.bundlejs.com/badge?q=nitro-graphql@0.0.4
468
878
  [bundle-href]: https://deno.bundlejs.com/badge?q=nitro-graphql@0.0.4
469
879
  [license-src]: https://img.shields.io/github/license/productdevbook/nitro-graphql.svg?style=flat&colorA=080f12&colorB=1fa669
470
- [license-href]: https://github.com/productdevbook/nitro-graphql/blob/main/LICENSE
880
+ [license-href]: https://github.com/productdevbook/nitro-graphql/blob/main/LICENSE
881
+ [docs-src]: https://img.shields.io/badge/docs-read-blue?style=flat&colorA=080f12&colorB=1fa669
882
+ [docs-href]: https://nitro-graphql.pages.dev
883
+ [beta-src]: https://img.shields.io/npm/v/nitro-graphql/beta?style=flat&logo=rocket&logoColor=white&label=beta&color=7c3aed&colorA=080f12
884
+ [beta-href]: https://github.com/productdevbook/nitro-graphql/releases
@@ -0,0 +1,26 @@
1
+ import { CLIContext } from "../index.mjs";
2
+
3
+ //#region src/cli/commands/generate.d.ts
4
+
5
+ /**
6
+ * Generate all types (server + client + optional runtime)
7
+ */
8
+ declare function generateAll(ctx: CLIContext, options?: {
9
+ silent?: boolean;
10
+ watch?: boolean;
11
+ runtime?: boolean;
12
+ }): Promise<void>;
13
+ /**
14
+ * Generate server types
15
+ */
16
+ declare function generateServer(ctx: CLIContext, options?: {
17
+ silent?: boolean;
18
+ }): Promise<void>;
19
+ /**
20
+ * Generate client types
21
+ */
22
+ declare function generateClient(ctx: CLIContext, options?: {
23
+ silent?: boolean;
24
+ }): Promise<void>;
25
+ //#endregion
26
+ export { generateAll, generateClient, generateServer };