Skip to content

Commit d85526d

Browse files
feat: streamline GraphQL configuration by removing unused client options and enhancing framework integration
1 parent 5ccdb39 commit d85526d

File tree

5 files changed

+21
-69
lines changed

5 files changed

+21
-69
lines changed

README.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ export default defineNitroConfig({
4646
endpoint: '/api/graphql', // default
4747
playground: true, // default (Apollo Sandbox)
4848
cors: false, // default
49-
cacheHeaders: {
50-
enabled: true, // default
51-
maxAge: 604800, // default (1 week)
52-
},
53-
client: {
54-
enabled: false, // default
55-
outputPath: undefined, // Will default to .nitro/types/graphql-client.generated.ts
56-
watchPatterns: undefined, // Will default to src/**/*.{graphql,gql} excluding server/graphql
57-
config: {
58-
documentMode: 'string',
59-
emitLegacyCommonJSImports: false,
60-
useTypeImports: true,
61-
enumsAsTypes: true,
62-
}
63-
}
6449
}
6550
})
6651
```
@@ -258,12 +243,6 @@ interface NitroGraphQLYogaOptions {
258243
methods?: string[]
259244
}
260245

261-
// Cache headers configuration
262-
cacheHeaders?: {
263-
enabled?: boolean // default: true
264-
maxAge?: number // default: 604800 (1 week)
265-
}
266-
267246
// Client type generation
268247
client?: {
269248
enabled?: boolean // default: false
@@ -362,14 +341,6 @@ Enable client type generation for your frontend queries:
362341
// nitro.config.ts
363342
export default defineNitroConfig({
364343
graphqlYoga: {
365-
client: {
366-
enabled: true,
367-
watchPatterns: [
368-
'client/**/*.graphql',
369-
'pages/**/*.vue',
370-
'components/**/*.vue'
371-
]
372-
}
373344
}
374345
})
375346
```

playground-nuxt/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default defineNuxtConfig({
1111
modules: ['nitro-graphql'],
1212
// GraphQL Yoga configuration
1313
graphql: {
14-
14+
framework: 'graphql-yoga',
1515
},
1616
},
1717

playground/nitro.config.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,7 @@ export default defineNitroConfig({
66
modules: ['nitro-graphql'],
77
compatibilityDate: '2025-07-01',
88
graphql: {
9-
endpoint: '/api/graphql',
10-
playground: true,
11-
cors: {
12-
origin: '*',
13-
credentials: true,
14-
},
15-
client: {
16-
enabled: true,
17-
watchPatterns: [
18-
'client/**/*.graphql',
19-
'client/**/*.gql',
20-
],
21-
},
9+
framework: 'graphql-yoga',
2210
},
2311
esbuild: {
2412
options: {

src/index.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,26 @@ export default defineNitroModule({
123123
new URL('routes', import.meta.url),
124124
)
125125
// Main GraphQL endpoint
126-
nitro.options.handlers.push({
127-
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || '/api/graphql',
128-
handler: join(runtime, 'graphql'),
129-
method: 'get',
130-
})
126+
if (nitro.options.graphql?.framework === 'graphql-yoga') {
127+
nitro.options.handlers.push({
128+
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || '/api/graphql',
129+
handler: join(runtime, 'graphql'),
130+
method: 'get',
131+
})
131132

132-
// Main GraphQL endpoint
133-
nitro.options.handlers.push({
134-
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || '/api/graphql',
135-
handler: join(runtime, 'graphql'),
136-
method: 'post',
137-
})
133+
// Main GraphQL endpoint
134+
nitro.options.handlers.push({
135+
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || '/api/graphql',
136+
handler: join(runtime, 'graphql'),
137+
method: 'post',
138+
})
138139

139-
nitro.options.handlers.push({
140-
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || '/api/graphql',
141-
handler: join(runtime, 'graphql'),
142-
method: 'options',
143-
})
140+
nitro.options.handlers.push({
141+
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || '/api/graphql',
142+
handler: join(runtime, 'graphql'),
143+
method: 'options',
144+
})
145+
}
144146

145147
// Health check endpoint
146148
nitro.options.handlers.push({

src/types/index.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface CodegenClientConfig extends TypeScriptPluginConfig, TypeScriptD
6060
}
6161

6262
export interface NitroGraphQLOptions {
63+
framework: 'graphql-yoga' | 'apollo-server'
6364
endpoint?: {
6465
graphql?: string
6566
healthCheck?: string
@@ -73,19 +74,9 @@ export interface NitroGraphQLOptions {
7374
exclude?: RegExp
7475
validate?: boolean
7576
}
76-
cacheHeaders?: {
77-
enabled?: boolean
78-
maxAge?: number
79-
}
8077
codegen?: {
8178
server?: CodegenServerConfig
8279
client?: CodegenClientConfig
8380
}
84-
client?: {
85-
enabled?: boolean
86-
outputPath?: string
87-
watchPatterns?: string[]
88-
nuxtPatterns?: string[]
89-
}
9081
yogaConfig?: Partial<YogaServerOptions<any, any>>
9182
}

0 commit comments

Comments
 (0)