nitro-graphql 2.0.0-beta.3 → 2.0.0-beta.30

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 (72) hide show
  1. package/README.md +476 -19
  2. package/dist/define.d.mts +296 -0
  3. package/dist/define.mjs +323 -0
  4. package/dist/ecosystem/nuxt.mjs +109 -0
  5. package/dist/index.d.mts +43 -0
  6. package/dist/index.mjs +63 -0
  7. package/dist/rollup.d.mts +12 -0
  8. package/dist/rollup.mjs +282 -0
  9. package/dist/routes/apollo-server.d.mts +6 -0
  10. package/dist/routes/{apollo-server.js → apollo-server.mjs} +7 -7
  11. package/dist/routes/debug.d.mts +61 -0
  12. package/dist/routes/debug.mjs +445 -0
  13. package/dist/routes/graphql-yoga.d.mts +6 -0
  14. package/dist/routes/{graphql-yoga.js → graphql-yoga.mjs} +11 -7
  15. package/dist/routes/health.d.mts +10 -0
  16. package/dist/routes/{health.js → health.mjs} +3 -2
  17. package/dist/setup.d.mts +11 -0
  18. package/dist/setup.mjs +392 -0
  19. package/dist/{utils/define.d.ts → types/define.d.mts} +4 -27
  20. package/dist/types/define.mjs +1 -0
  21. package/dist/types/index.d.mts +246 -0
  22. package/dist/types/index.mjs +1 -0
  23. package/dist/types/standard-schema.mjs +1 -0
  24. package/dist/utils/{apollo.d.ts → apollo.d.mts} +2 -2
  25. package/dist/utils/apollo.mjs +59 -0
  26. package/dist/utils/{client-codegen.d.ts → client-codegen.d.mts} +6 -3
  27. package/dist/utils/{client-codegen.js → client-codegen.mjs} +6 -6
  28. package/dist/utils/errors.d.mts +73 -0
  29. package/dist/utils/errors.mjs +89 -0
  30. package/dist/utils/file-generator.d.mts +37 -0
  31. package/dist/utils/file-generator.mjs +72 -0
  32. package/dist/utils/{index.d.ts → index.d.mts} +4 -3
  33. package/dist/utils/{index.js → index.mjs} +76 -37
  34. package/dist/utils/path-resolver.d.mts +70 -0
  35. package/dist/utils/path-resolver.mjs +127 -0
  36. package/dist/utils/{server-codegen.d.ts → server-codegen.d.mts} +1 -1
  37. package/dist/utils/{server-codegen.js → server-codegen.mjs} +3 -3
  38. package/dist/utils/type-generation.d.mts +12 -0
  39. package/dist/utils/type-generation.mjs +420 -0
  40. package/dist/virtual/debug-info.d.mts +9 -0
  41. package/dist/virtual/debug-info.mjs +26 -0
  42. package/dist/virtual/graphql-config.d.mts +9 -0
  43. package/dist/virtual/graphql-config.mjs +10 -0
  44. package/dist/virtual/module-config.d.mts +9 -0
  45. package/dist/virtual/module-config.mjs +10 -0
  46. package/dist/virtual/server-directives.d.mts +11 -0
  47. package/dist/virtual/server-directives.mjs +10 -0
  48. package/dist/virtual/server-resolvers.d.mts +11 -0
  49. package/dist/virtual/server-resolvers.mjs +10 -0
  50. package/dist/virtual/server-schemas.d.mts +11 -0
  51. package/dist/virtual/server-schemas.mjs +10 -0
  52. package/package.json +79 -70
  53. package/dist/ecosystem/nuxt.js +0 -67
  54. package/dist/index.d.ts +0 -8
  55. package/dist/index.js +0 -264
  56. package/dist/rollup.js +0 -114
  57. package/dist/routes/apollo-server.d.ts +0 -6
  58. package/dist/routes/graphql-yoga.d.ts +0 -6
  59. package/dist/routes/health.d.ts +0 -6
  60. package/dist/types/index.d.ts +0 -128
  61. package/dist/utils/apollo.js +0 -61
  62. package/dist/utils/define.js +0 -57
  63. package/dist/utils/type-generation.d.ts +0 -7
  64. package/dist/utils/type-generation.js +0 -287
  65. /package/dist/ecosystem/{nuxt.d.ts → nuxt.d.mts} +0 -0
  66. /package/dist/graphql/{index.d.ts → index.d.mts} +0 -0
  67. /package/dist/graphql/{index.js → index.mjs} +0 -0
  68. /package/dist/graphql/{server.d.ts → server.d.mts} +0 -0
  69. /package/dist/graphql/{server.js → server.mjs} +0 -0
  70. /package/dist/types/{standard-schema.d.ts → standard-schema.d.mts} +0 -0
  71. /package/dist/utils/{directive-parser.d.ts → directive-parser.d.mts} +0 -0
  72. /package/dist/utils/{directive-parser.js → directive-parser.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="./.docs/public/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,16 +71,47 @@ 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'
78
+ modules: [
79
+ graphql({
80
+ framework: 'graphql-yoga', // or 'apollo-server'
81
+ }),
82
+ ],
83
+ })
84
+ ```
85
+
86
+ </details>
87
+
88
+ <details>
89
+ <summary>⚡ <strong>Vite + Nitro Project</strong></summary>
90
+
91
+ ```ts
92
+ // vite.config.ts
93
+ import { defineConfig } from 'vite'
94
+ import { nitro } from 'nitro/vite'
95
+ import graphql from 'nitro-graphql'
96
+ import { graphql as graphqlVite } from 'nitro-graphql/vite'
97
+
98
+ export default defineConfig({
99
+ plugins: [
100
+ graphqlVite(), // ⚠️ Must be before nitro()
101
+ nitro(),
102
+ ],
103
+ nitro: {
104
+ modules: [
105
+ graphql({
106
+ framework: 'graphql-yoga',
107
+ }),
108
+ ],
61
109
  },
62
110
  })
63
111
  ```
64
112
 
113
+ > **⚠️ Important**: The `graphql()` plugin must be placed **before** `nitro()` to prevent Vite from trying to parse GraphQL files as JavaScript.
114
+
65
115
  </details>
66
116
 
67
117
  <details>
@@ -99,6 +149,8 @@ type Mutation {
99
149
 
100
150
  ```ts
101
151
  // server/graphql/hello.resolver.ts
152
+ import { defineResolver } from 'nitro-graphql/define'
153
+
102
154
  export const helloResolver = defineResolver({
103
155
  Query: {
104
156
  hello: () => 'Hello from GraphQL!',
@@ -117,6 +169,7 @@ pnpm dev
117
169
  - **Endpoint**: `http://localhost:3000/api/graphql`
118
170
  - **Playground**: `http://localhost:3000/api/graphql` (browser)
119
171
  - **Health**: `http://localhost:3000/api/graphql/health`
172
+ - **Debug Dashboard**: `http://localhost:3000/_nitro/graphql/debug` (dev mode only)
120
173
 
121
174
  ## 🎮 Examples
122
175
 
@@ -125,8 +178,17 @@ Try these working examples:
125
178
  | Example | Description | Demo |
126
179
  |---------|-------------|------|
127
180
  | [**Nitro Basic**](./playgrounds/nitro/) | Standalone Nitro with GraphQL | `pnpm playground:nitro` |
181
+ | [**Vite + Nitro**](./playgrounds/vite/) | Vite with Nitro GraphQL integration | `cd playgrounds/vite && pnpm dev` |
128
182
  | [**Nuxt Integration**](./playgrounds/nuxt/) | Full Nuxt app with client types | `pnpm playground:nuxt` |
129
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
130
192
 
131
193
  ## 🏗️ Building Your First Feature
132
194
 
@@ -160,6 +222,8 @@ extend type Mutation {
160
222
  ### 2. Create Resolvers
161
223
  ```ts
162
224
  // server/graphql/users/user.resolver.ts
225
+ import { defineQuery, defineMutation } from 'nitro-graphql/define'
226
+
163
227
  export const userQueries = defineQuery({
164
228
  users: async (_, __, { storage }) => {
165
229
  return await storage.getItem('users') || []
@@ -210,6 +274,261 @@ query {
210
274
 
211
275
  ## 🚀 Advanced Features
212
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
+
213
532
  <details>
214
533
  <summary><strong>🎭 Custom Directives</strong></summary>
215
534
 
@@ -217,6 +536,8 @@ Create reusable GraphQL directives:
217
536
 
218
537
  ```ts
219
538
  // server/graphql/directives/auth.directive.ts
539
+ import { defineDirective } from 'nitro-graphql/define'
540
+
220
541
  export const authDirective = defineDirective({
221
542
  name: 'auth',
222
543
  locations: ['FIELD_DEFINITION'],
@@ -274,14 +595,19 @@ Build federated GraphQL services:
274
595
 
275
596
  ```ts
276
597
  // nitro.config.ts
598
+ import graphql from 'nitro-graphql'
599
+ import { defineNitroConfig } from 'nitro/config'
600
+
277
601
  export default defineNitroConfig({
278
- graphql: {
279
- framework: 'apollo-server',
280
- federation: {
281
- enabled: true,
282
- serviceName: 'users-service'
283
- }
284
- }
602
+ modules: [
603
+ graphql({
604
+ framework: 'apollo-server',
605
+ federation: {
606
+ enabled: true,
607
+ serviceName: 'users-service',
608
+ },
609
+ }),
610
+ ],
285
611
  })
286
612
  ```
287
613
 
@@ -291,7 +617,11 @@ export default defineNitroConfig({
291
617
 
292
618
  ### Core Utilities
293
619
 
294
- 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, defineType, defineDirective } from 'nitro-graphql/define'
624
+ ```
295
625
 
296
626
  | Function | Purpose | Example |
297
627
  |----------|---------|---------|
@@ -300,6 +630,11 @@ All utilities are auto-imported in resolver files:
300
630
  | `defineMutation` | Mutation-only resolvers | `defineMutation({ createUser: (...) => {...} })` |
301
631
  | `defineType` | Custom type resolvers | `defineType({ User: { posts: (parent) => [...] } })` |
302
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/utils`:
637
+ - `createDefaultMaskError()` - Error handler for ZodError and HTTPError (use in `defineGraphQLConfig`)
303
638
 
304
639
  ### Type Generation
305
640
 
@@ -353,10 +688,107 @@ server/
353
688
  - ✅ Check file naming: `*.graphql`, `*.resolver.ts`
354
689
  - ✅ Verify exports are named exports
355
690
 
356
- **Import errors**
357
- - ✅ 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`)
358
694
  - ✅ Use named exports in resolvers
359
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
+
704
+ **Vite: "Parse failure: Expected ';', '}' or <eof>" on GraphQL files**
705
+ - ✅ Add `graphql()` plugin from `nitro-graphql/vite`
706
+ - ✅ Ensure `graphql()` is placed **before** `nitro()` in plugins array
707
+ - ✅ Example:
708
+ ```ts
709
+ import { graphql } from 'nitro-graphql/vite'
710
+
711
+ export default defineConfig({
712
+ plugins: [
713
+ graphql(), // ← Must be first
714
+ nitro(),
715
+ ]
716
+ })
717
+ ```
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
+ - `defineType` - 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
+
360
792
  </details>
361
793
 
362
794
  ## 🌟 Production Usage
@@ -365,6 +797,27 @@ This package powers production applications:
365
797
 
366
798
  - [**Nitroping**](https://github.com/productdevbook/nitroping) - Self-hosted push notification service
367
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
+
368
821
  ## 🛠️ Development
369
822
 
370
823
  ```bash
@@ -424,4 +877,8 @@ pnpm lint
424
877
  [bundle-src]: https://deno.bundlejs.com/badge?q=nitro-graphql@0.0.4
425
878
  [bundle-href]: https://deno.bundlejs.com/badge?q=nitro-graphql@0.0.4
426
879
  [license-src]: https://img.shields.io/github/license/productdevbook/nitro-graphql.svg?style=flat&colorA=080f12&colorB=1fa669
427
- [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