nitro-graphql 2.0.0-beta.4 → 2.0.0-beta.41
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.
- package/README.md +438 -27
- package/dist/cli/commands/generate.d.mts +26 -0
- package/dist/cli/commands/generate.mjs +196 -0
- package/dist/cli/commands/index.d.mts +4 -0
- package/dist/cli/commands/index.mjs +5 -0
- package/dist/cli/commands/init.d.mts +46 -0
- package/dist/cli/commands/init.mjs +195 -0
- package/dist/cli/commands/validate.d.mts +10 -0
- package/dist/cli/commands/validate.mjs +69 -0
- package/dist/cli/completions.d.mts +7 -0
- package/dist/cli/completions.mjs +34 -0
- package/dist/cli/config.d.mts +75 -0
- package/dist/cli/config.mjs +20 -0
- package/dist/cli/index.d.mts +24 -0
- package/dist/cli/index.mjs +253 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +3 -0
- package/dist/core/codegen/client.d.mts +23 -0
- package/dist/core/codegen/client.mjs +150 -0
- package/dist/core/codegen/document-loader.d.mts +10 -0
- package/dist/core/codegen/document-loader.mjs +18 -0
- package/dist/core/codegen/index.d.mts +8 -0
- package/dist/core/codegen/index.mjs +9 -0
- package/dist/core/codegen/plugin.d.mts +20 -0
- package/dist/core/codegen/plugin.mjs +30 -0
- package/dist/core/codegen/runtime.d.mts +20 -0
- package/dist/core/codegen/runtime.mjs +60 -0
- package/dist/core/codegen/schema-loader.d.mts +28 -0
- package/dist/core/codegen/schema-loader.mjs +128 -0
- package/dist/core/codegen/server.d.mts +28 -0
- package/dist/core/codegen/server.mjs +143 -0
- package/dist/core/codegen/validation.d.mts +13 -0
- package/dist/core/codegen/validation.mjs +96 -0
- package/dist/core/config.d.mts +50 -0
- package/dist/core/config.mjs +82 -0
- package/dist/core/constants.d.mts +188 -0
- package/dist/core/constants.mjs +210 -0
- package/dist/core/index.d.mts +33 -0
- package/dist/core/index.mjs +27 -0
- package/dist/core/manifest.d.mts +46 -0
- package/dist/core/manifest.mjs +76 -0
- package/dist/core/scanning/ast-scanner.d.mts +28 -0
- package/dist/core/scanning/ast-scanner.mjs +122 -0
- package/dist/core/scanning/common.d.mts +37 -0
- package/dist/core/scanning/common.mjs +60 -0
- package/dist/core/scanning/directives.d.mts +10 -0
- package/dist/core/scanning/directives.mjs +29 -0
- package/dist/core/scanning/documents.d.mts +21 -0
- package/dist/core/scanning/documents.mjs +43 -0
- package/dist/core/scanning/index.d.mts +7 -0
- package/dist/core/scanning/index.mjs +8 -0
- package/dist/core/scanning/resolvers.d.mts +15 -0
- package/dist/core/scanning/resolvers.mjs +59 -0
- package/dist/core/scanning/schemas.d.mts +14 -0
- package/dist/core/scanning/schemas.mjs +64 -0
- package/dist/core/schema/builder.d.mts +53 -0
- package/dist/core/schema/builder.mjs +70 -0
- package/dist/core/schema/federation.d.mts +34 -0
- package/dist/core/schema/federation.mjs +40 -0
- package/dist/core/schema/index.d.mts +3 -0
- package/dist/core/schema/index.mjs +4 -0
- package/dist/core/types/adapter.d.mts +58 -0
- package/dist/core/types/codegen.d.mts +133 -0
- package/dist/core/types/config.d.mts +210 -0
- package/dist/core/types/config.mjs +1 -0
- package/dist/{utils/define.d.ts → core/types/define.d.mts} +3 -30
- package/dist/core/types/define.mjs +1 -0
- package/dist/core/types/index.d.mts +5 -0
- package/dist/core/types/index.mjs +1 -0
- package/dist/core/types/scanning.d.mts +69 -0
- package/dist/core/types/scanning.mjs +1 -0
- package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +21 -4
- package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +25 -34
- package/dist/core/utils/errors.d.mts +77 -0
- package/dist/core/utils/errors.mjs +93 -0
- package/dist/core/utils/file-io.d.mts +24 -0
- package/dist/core/utils/file-io.mjs +47 -0
- package/dist/core/utils/imports.d.mts +15 -0
- package/dist/core/utils/imports.mjs +25 -0
- package/dist/core/utils/index.d.mts +7 -0
- package/dist/core/utils/index.mjs +8 -0
- package/dist/core/utils/logger.d.mts +19 -0
- package/dist/core/utils/logger.mjs +38 -0
- package/dist/core/utils/ofetch-templates.d.mts +30 -0
- package/dist/core/utils/ofetch-templates.mjs +135 -0
- package/dist/core/validation/external-services.d.mts +11 -0
- package/dist/core/validation/external-services.mjs +34 -0
- package/dist/core/validation/index.d.mts +2 -0
- package/dist/core/validation/index.mjs +3 -0
- package/dist/define.d.mts +294 -0
- package/dist/define.mjs +323 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +6 -0
- package/dist/nitro/adapter.d.mts +30 -0
- package/dist/nitro/adapter.mjs +97 -0
- package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
- package/dist/nitro/apollo.mjs +59 -0
- package/dist/nitro/codegen.d.mts +19 -0
- package/dist/nitro/codegen.mjs +141 -0
- package/dist/nitro/config.d.mts +51 -0
- package/dist/nitro/config.mjs +57 -0
- package/dist/nitro/index.d.mts +46 -0
- package/dist/nitro/index.mjs +65 -0
- package/dist/nitro/paths.d.mts +54 -0
- package/dist/nitro/paths.mjs +92 -0
- package/dist/nitro/rollup.d.mts +6 -0
- package/dist/nitro/rollup.mjs +95 -0
- package/dist/nitro/routes/apollo-server.d.mts +6 -0
- package/dist/nitro/routes/apollo-server.mjs +71 -0
- package/dist/nitro/routes/debug-template.d.mts +15 -0
- package/dist/nitro/routes/debug-template.mjs +385 -0
- package/dist/nitro/routes/debug.d.mts +55 -0
- package/dist/nitro/routes/debug.mjs +102 -0
- package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
- package/dist/nitro/routes/graphql-yoga.mjs +62 -0
- package/dist/nitro/routes/health.d.mts +10 -0
- package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
- package/dist/nitro/setup/extend-loader.d.mts +19 -0
- package/dist/nitro/setup/extend-loader.mjs +129 -0
- package/dist/nitro/setup/file-watcher.d.mts +16 -0
- package/dist/nitro/setup/file-watcher.mjs +98 -0
- package/dist/nitro/setup/logging.d.mts +17 -0
- package/dist/nitro/setup/logging.mjs +66 -0
- package/dist/nitro/setup/rollup-integration.d.mts +16 -0
- package/dist/nitro/setup/rollup-integration.mjs +90 -0
- package/dist/nitro/setup/routes.d.mts +10 -0
- package/dist/nitro/setup/routes.mjs +35 -0
- package/dist/nitro/setup/ts-config.d.mts +11 -0
- package/dist/nitro/setup/ts-config.mjs +69 -0
- package/dist/nitro/setup.d.mts +12 -0
- package/dist/nitro/setup.mjs +234 -0
- package/dist/nitro/types.d.mts +374 -0
- package/dist/nitro/types.mjs +1 -0
- package/dist/nitro/virtual/generators.d.mts +31 -0
- package/dist/nitro/virtual/generators.mjs +113 -0
- package/dist/nitro/virtual/stubs.d.mts +20 -0
- package/dist/nitro/virtual/stubs.mjs +31 -0
- package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
- package/dist/nuxt.mjs +109 -0
- package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
- package/dist/stubs/index.mjs +1 -0
- package/package.json +102 -77
- package/dist/ecosystem/nuxt.js +0 -67
- package/dist/graphql/index.d.ts +0 -5
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -264
- package/dist/rollup.js +0 -119
- package/dist/routes/apollo-server.d.ts +0 -6
- package/dist/routes/apollo-server.js +0 -89
- package/dist/routes/graphql-yoga.d.ts +0 -6
- package/dist/routes/graphql-yoga.js +0 -91
- package/dist/routes/health.d.ts +0 -6
- package/dist/types/index.d.ts +0 -128
- package/dist/types/standard-schema.d.ts +0 -59
- package/dist/utils/apollo.js +0 -61
- package/dist/utils/client-codegen.d.ts +0 -38
- package/dist/utils/client-codegen.js +0 -290
- package/dist/utils/define.js +0 -57
- package/dist/utils/index.d.ts +0 -39
- package/dist/utils/index.js +0 -250
- package/dist/utils/server-codegen.d.ts +0 -7
- package/dist/utils/server-codegen.js +0 -136
- package/dist/utils/type-generation.d.ts +0 -7
- package/dist/utils/type-generation.js +0 -287
- package/dist/vite.d.ts +0 -25
- package/dist/vite.js +0 -40
- /package/dist/{graphql/index.js → core/types/adapter.mjs} +0 -0
- /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
|
-
[
|
|
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
|
|
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: [
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
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
|
-
|
|
100
|
+
graphqlVite(), // ⚠️ Must be before nitro()
|
|
79
101
|
nitro(),
|
|
80
102
|
],
|
|
81
103
|
nitro: {
|
|
82
|
-
modules: [
|
|
83
|
-
|
|
84
|
-
|
|
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,258 @@ 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
|
+
serverDir: 'src/server/graphql',
|
|
361
|
+
clientDir: 'src/client/graphql',
|
|
362
|
+
typesDir: '.build/types',
|
|
363
|
+
|
|
364
|
+
// Method 2: Specific file paths
|
|
365
|
+
scaffold: {
|
|
366
|
+
serverSchema: 'lib/graphql/schema.ts',
|
|
367
|
+
serverConfig: 'lib/graphql/config.ts',
|
|
368
|
+
},
|
|
369
|
+
|
|
370
|
+
sdk: {
|
|
371
|
+
main: 'app/graphql/organization/sdk.ts',
|
|
372
|
+
external: 'app/graphql/{serviceName}/client-sdk.ts',
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
types: {
|
|
376
|
+
server: 'types/graphql-server.d.ts',
|
|
377
|
+
client: 'types/graphql-client.d.ts',
|
|
378
|
+
},
|
|
379
|
+
}),
|
|
380
|
+
],
|
|
381
|
+
})
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Path Placeholders
|
|
385
|
+
|
|
386
|
+
Use placeholders in custom paths:
|
|
387
|
+
|
|
388
|
+
| Placeholder | Description | Example |
|
|
389
|
+
|------------|-------------|---------|
|
|
390
|
+
| `{serviceName}` | External service name | `github`, `stripe` |
|
|
391
|
+
| `{buildDir}` | Build directory | `.nitro` or `.nuxt` |
|
|
392
|
+
| `{rootDir}` | Root directory | `/Users/you/project` |
|
|
393
|
+
| `{framework}` | Framework name | `nuxt` or `nitro` |
|
|
394
|
+
| `{typesDir}` | Types directory | `.nitro/types` |
|
|
395
|
+
| `{serverDir}` | Server GraphQL dir | `server/graphql` |
|
|
396
|
+
| `{clientDir}` | Client GraphQL dir | `app/graphql` |
|
|
397
|
+
|
|
398
|
+
Example:
|
|
399
|
+
```ts
|
|
400
|
+
sdk: {
|
|
401
|
+
external: '{clientDir}/{serviceName}/sdk.ts'
|
|
402
|
+
}
|
|
403
|
+
// → app/graphql/github/sdk.ts
|
|
404
|
+
// → app/graphql/stripe/sdk.ts
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Service-Specific Paths
|
|
408
|
+
|
|
409
|
+
Customize paths for individual external services:
|
|
410
|
+
|
|
411
|
+
```ts
|
|
412
|
+
export default defineNuxtConfig({
|
|
413
|
+
nitro: {
|
|
414
|
+
graphql: {
|
|
415
|
+
framework: 'graphql-yoga',
|
|
416
|
+
|
|
417
|
+
// Global default for all external services
|
|
418
|
+
sdk: {
|
|
419
|
+
external: 'app/graphql/{serviceName}/sdk.ts'
|
|
420
|
+
},
|
|
421
|
+
|
|
422
|
+
externalServices: [
|
|
423
|
+
{
|
|
424
|
+
name: 'github',
|
|
425
|
+
endpoint: 'https://api.github.com/graphql',
|
|
426
|
+
schema: 'https://api.github.com/graphql',
|
|
427
|
+
|
|
428
|
+
// GitHub-specific paths (override global config)
|
|
429
|
+
paths: {
|
|
430
|
+
sdk: 'app/graphql/organization/github-sdk.ts',
|
|
431
|
+
types: 'types/github.d.ts',
|
|
432
|
+
ofetch: 'app/graphql/organization/github-client.ts'
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
name: 'stripe',
|
|
437
|
+
endpoint: 'https://api.stripe.com/graphql',
|
|
438
|
+
schema: 'https://api.stripe.com/graphql',
|
|
439
|
+
|
|
440
|
+
// Stripe-specific paths
|
|
441
|
+
paths: {
|
|
442
|
+
sdk: 'app/graphql/payments/stripe-sdk.ts',
|
|
443
|
+
types: 'types/payments/stripe.d.ts',
|
|
444
|
+
// ofetch uses global config
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
name: 'shopify',
|
|
449
|
+
endpoint: 'https://api.shopify.com/graphql',
|
|
450
|
+
// No paths → uses global config
|
|
451
|
+
// → app/graphql/shopify/sdk.ts
|
|
452
|
+
}
|
|
453
|
+
]
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
})
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### Path Resolution Priority
|
|
460
|
+
|
|
461
|
+
When resolving file paths, the system follows this priority order:
|
|
462
|
+
|
|
463
|
+
1. **Service-specific path** (for external services): `service.paths.sdk`
|
|
464
|
+
2. **Category config**: `sdk.external` or `sdk.main`
|
|
465
|
+
3. **Global paths**: `clientDir`
|
|
466
|
+
4. **Framework defaults**: Nuxt vs Nitro defaults
|
|
467
|
+
|
|
468
|
+
Example:
|
|
469
|
+
```ts
|
|
470
|
+
// Given this config:
|
|
471
|
+
{
|
|
472
|
+
clientDir: 'custom/graphql',
|
|
473
|
+
sdk: { external: '{clientDir}/{serviceName}/sdk.ts' },
|
|
474
|
+
externalServices: [
|
|
475
|
+
{
|
|
476
|
+
name: 'github',
|
|
477
|
+
paths: { sdk: 'app/org/github-sdk.ts' } // ← Wins (priority 1)
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
name: 'stripe',
|
|
481
|
+
// Uses sdk.external (priority 2)
|
|
482
|
+
// → custom/graphql/stripe/sdk.ts
|
|
483
|
+
}
|
|
484
|
+
]
|
|
485
|
+
}
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
### Use Cases
|
|
489
|
+
|
|
490
|
+
**Monorepo structure:**
|
|
491
|
+
```ts
|
|
492
|
+
{
|
|
493
|
+
serverDir: 'packages/api/src/graphql',
|
|
494
|
+
clientDir: 'packages/web/src/graphql',
|
|
495
|
+
typesDir: 'packages/types/src/generated',
|
|
496
|
+
}
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
**Multiple external service organizations:**
|
|
500
|
+
```ts
|
|
501
|
+
externalServices: [
|
|
502
|
+
{
|
|
503
|
+
name: 'github',
|
|
504
|
+
paths: { sdk: 'app/graphql/vcs/github-sdk.ts' }
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
name: 'gitlab',
|
|
508
|
+
paths: { sdk: 'app/graphql/vcs/gitlab-sdk.ts' }
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
name: 'stripe',
|
|
512
|
+
paths: { sdk: 'app/graphql/billing/stripe-sdk.ts' }
|
|
513
|
+
}
|
|
514
|
+
]
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
**Library development (no scaffolding):**
|
|
518
|
+
```ts
|
|
519
|
+
{
|
|
520
|
+
scaffold: false,
|
|
521
|
+
clientUtils: false,
|
|
522
|
+
sdk: { enabled: true }, // Only generate SDKs
|
|
523
|
+
types: { enabled: true }, // Only generate types
|
|
524
|
+
}
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
</details>
|
|
528
|
+
|
|
241
529
|
<details>
|
|
242
530
|
<summary><strong>🎭 Custom Directives</strong></summary>
|
|
243
531
|
|
|
@@ -245,6 +533,8 @@ Create reusable GraphQL directives:
|
|
|
245
533
|
|
|
246
534
|
```ts
|
|
247
535
|
// server/graphql/directives/auth.directive.ts
|
|
536
|
+
import { defineDirective } from 'nitro-graphql/define'
|
|
537
|
+
|
|
248
538
|
export const authDirective = defineDirective({
|
|
249
539
|
name: 'auth',
|
|
250
540
|
locations: ['FIELD_DEFINITION'],
|
|
@@ -302,14 +592,19 @@ Build federated GraphQL services:
|
|
|
302
592
|
|
|
303
593
|
```ts
|
|
304
594
|
// nitro.config.ts
|
|
595
|
+
import graphql from 'nitro-graphql'
|
|
596
|
+
import { defineNitroConfig } from 'nitro/config'
|
|
597
|
+
|
|
305
598
|
export default defineNitroConfig({
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
599
|
+
modules: [
|
|
600
|
+
graphql({
|
|
601
|
+
framework: 'apollo-server',
|
|
602
|
+
federation: {
|
|
603
|
+
enabled: true,
|
|
604
|
+
serviceName: 'users-service',
|
|
605
|
+
},
|
|
606
|
+
}),
|
|
607
|
+
],
|
|
313
608
|
})
|
|
314
609
|
```
|
|
315
610
|
|
|
@@ -319,15 +614,24 @@ export default defineNitroConfig({
|
|
|
319
614
|
|
|
320
615
|
### Core Utilities
|
|
321
616
|
|
|
322
|
-
|
|
617
|
+
> **⚠️ Breaking Change**: Utilities are **NOT auto-imported**. You must explicitly import them from `nitro-graphql/define`:
|
|
618
|
+
|
|
619
|
+
```typescript
|
|
620
|
+
import { defineResolver, defineQuery, defineMutation, defineField, defineDirective } from 'nitro-graphql/define'
|
|
621
|
+
```
|
|
323
622
|
|
|
324
623
|
| Function | Purpose | Example |
|
|
325
624
|
|----------|---------|---------|
|
|
326
625
|
| `defineResolver` | Complete resolvers | `defineResolver({ Query: {...}, Mutation: {...} })` |
|
|
327
626
|
| `defineQuery` | Query-only resolvers | `defineQuery({ users: () => [...] })` |
|
|
328
627
|
| `defineMutation` | Mutation-only resolvers | `defineMutation({ createUser: (...) => {...} })` |
|
|
329
|
-
| `
|
|
628
|
+
| `defineField` | Custom type resolvers | `defineField({ User: { posts: (parent) => [...] } })` |
|
|
330
629
|
| `defineDirective` | Custom directives | `defineDirective({ name: 'auth', ... })` |
|
|
630
|
+
| `defineGraphQLConfig` | GraphQL server config | `defineGraphQLConfig({ maskedErrors: {...} })` |
|
|
631
|
+
| `defineSchema` | Schema with Zod integration | `defineSchema({ Book: selectBookSchema })` |
|
|
632
|
+
|
|
633
|
+
**Additional Utilities** from `nitro-graphql/core`:
|
|
634
|
+
- `createDefaultMaskError()` - Error handler for ZodError and HTTPError (use in `defineGraphQLConfig`)
|
|
331
635
|
|
|
332
636
|
### Type Generation
|
|
333
637
|
|
|
@@ -381,10 +685,19 @@ server/
|
|
|
381
685
|
- ✅ Check file naming: `*.graphql`, `*.resolver.ts`
|
|
382
686
|
- ✅ Verify exports are named exports
|
|
383
687
|
|
|
384
|
-
**Import errors**
|
|
385
|
-
- ✅
|
|
688
|
+
**Import errors / "defineQuery is not defined"**
|
|
689
|
+
- ✅ **Requires explicit imports**: Add `import { defineQuery } from 'nitro-graphql/define'` to resolver files
|
|
690
|
+
- ✅ Use correct import path: `nitro-graphql/define` (not `nitro-graphql`)
|
|
386
691
|
- ✅ Use named exports in resolvers
|
|
387
692
|
|
|
693
|
+
Example fix:
|
|
694
|
+
```typescript
|
|
695
|
+
// Add this to the top of your resolver file
|
|
696
|
+
import { defineQuery, defineMutation } from 'nitro-graphql/define'
|
|
697
|
+
|
|
698
|
+
export const myQueries = defineQuery({ ... })
|
|
699
|
+
```
|
|
700
|
+
|
|
388
701
|
**Vite: "Parse failure: Expected ';', '}' or <eof>" on GraphQL files**
|
|
389
702
|
- ✅ Add `graphql()` plugin from `nitro-graphql/vite`
|
|
390
703
|
- ✅ Ensure `graphql()` is placed **before** `nitro()` in plugins array
|
|
@@ -400,6 +713,79 @@ server/
|
|
|
400
713
|
})
|
|
401
714
|
```
|
|
402
715
|
|
|
716
|
+
**RollupError: "[exportName]" is not exported by "[file].resolver.ts"**
|
|
717
|
+
|
|
718
|
+
This error occurs when the resolver scanner can't find the expected export in your resolver file. Common causes:
|
|
719
|
+
|
|
720
|
+
1. **Using default export instead of named export** ❌
|
|
721
|
+
```ts
|
|
722
|
+
// ❌ WRONG - Will not be detected
|
|
723
|
+
export default defineQuery({
|
|
724
|
+
users: () => [...]
|
|
725
|
+
})
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
```ts
|
|
729
|
+
// ✅ CORRECT - Use named export
|
|
730
|
+
export const userQueries = defineQuery({
|
|
731
|
+
users: () => [...]
|
|
732
|
+
})
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
2. **Not using a define function** ❌
|
|
736
|
+
```ts
|
|
737
|
+
// ❌ WRONG - Plain object won't be detected
|
|
738
|
+
export const resolvers = {
|
|
739
|
+
Query: {
|
|
740
|
+
users: () => [...]
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
```ts
|
|
746
|
+
// ✅ CORRECT - Use defineResolver, defineQuery, etc.
|
|
747
|
+
export const userResolver = defineResolver({
|
|
748
|
+
Query: {
|
|
749
|
+
users: () => [...]
|
|
750
|
+
}
|
|
751
|
+
})
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
3. **File naming doesn't match export** ❌
|
|
755
|
+
```ts
|
|
756
|
+
// ❌ File: uploadFile.resolver.ts but export is named differently
|
|
757
|
+
export const fileUploader = defineMutation({...})
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
```ts
|
|
761
|
+
// ✅ CORRECT - Export name can be anything, as long as it uses a define function
|
|
762
|
+
export const uploadFile = defineMutation({...})
|
|
763
|
+
export const fileUploader = defineMutation({...}) // Both work!
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
4. **Syntax errors preventing parsing**
|
|
767
|
+
- Check for TypeScript compilation errors in the file
|
|
768
|
+
- Ensure imports are valid
|
|
769
|
+
- Verify no missing brackets or syntax issues
|
|
770
|
+
|
|
771
|
+
**How resolver scanning works:**
|
|
772
|
+
- The module uses `oxc-parser` to scan `.resolver.ts` files
|
|
773
|
+
- It looks for **named exports** using these functions:
|
|
774
|
+
- `defineResolver` - Complete resolver with Query, Mutation, etc.
|
|
775
|
+
- `defineQuery` - Query-only resolvers
|
|
776
|
+
- `defineMutation` - Mutation-only resolvers
|
|
777
|
+
- `defineField` - Custom type resolvers
|
|
778
|
+
- `defineSubscription` - Subscription resolvers
|
|
779
|
+
- `defineDirective` - Directive resolvers
|
|
780
|
+
- Only exports using these functions are included in the virtual module
|
|
781
|
+
|
|
782
|
+
**Debugging steps:**
|
|
783
|
+
1. Check your resolver file uses named exports: `export const name = defineQuery({...})`
|
|
784
|
+
2. Verify you're using one of the define functions listed above
|
|
785
|
+
3. Look for TypeScript/syntax errors in the file
|
|
786
|
+
4. Restart the dev server after fixing
|
|
787
|
+
5. If issues persist, simplify the resolver to test (single query)
|
|
788
|
+
|
|
403
789
|
</details>
|
|
404
790
|
|
|
405
791
|
## 🌟 Production Usage
|
|
@@ -408,6 +794,27 @@ This package powers production applications:
|
|
|
408
794
|
|
|
409
795
|
- [**Nitroping**](https://github.com/productdevbook/nitroping) - Self-hosted push notification service
|
|
410
796
|
|
|
797
|
+
### Working with Your GraphQL API
|
|
798
|
+
|
|
799
|
+
Once set up, you can ask Claude Code for help with:
|
|
800
|
+
|
|
801
|
+
```
|
|
802
|
+
"Add authentication to my GraphQL resolvers"
|
|
803
|
+
"Create a custom @auth directive for field-level permissions"
|
|
804
|
+
"Set up type generation for client-side queries"
|
|
805
|
+
"Add pagination to my users query"
|
|
806
|
+
"Connect to an external GitHub GraphQL API"
|
|
807
|
+
"Debug: my types aren't generating in .nitro/types/"
|
|
808
|
+
"Optimize resolver performance using DataLoader"
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
### Tips for Better Results
|
|
812
|
+
|
|
813
|
+
- **Start specific**: Include your framework (Nuxt/Nitro), version, and goal
|
|
814
|
+
- **Reference docs**: Mention "following nitro-graphql conventions" to align with best practices
|
|
815
|
+
- **Show errors**: Paste error messages for faster debugging
|
|
816
|
+
- **Test iteratively**: Run `pnpm dev` after each change to verify
|
|
817
|
+
|
|
411
818
|
## 🛠️ Development
|
|
412
819
|
|
|
413
820
|
```bash
|
|
@@ -467,4 +874,8 @@ pnpm lint
|
|
|
467
874
|
[bundle-src]: https://deno.bundlejs.com/badge?q=nitro-graphql@0.0.4
|
|
468
875
|
[bundle-href]: https://deno.bundlejs.com/badge?q=nitro-graphql@0.0.4
|
|
469
876
|
[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
|
|
877
|
+
[license-href]: https://github.com/productdevbook/nitro-graphql/blob/main/LICENSE
|
|
878
|
+
[docs-src]: https://img.shields.io/badge/docs-read-blue?style=flat&colorA=080f12&colorB=1fa669
|
|
879
|
+
[docs-href]: https://nitro-graphql.pages.dev
|
|
880
|
+
[beta-src]: https://img.shields.io/npm/v/nitro-graphql/beta?style=flat&logo=rocket&logoColor=white&label=beta&color=7c3aed&colorA=080f12
|
|
881
|
+
[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 };
|