1
1
import type { Nitro } from 'nitropack/types'
2
+ import type { NitroGraphQLOptions } from './types'
2
3
import { writeFileSync } from 'node:fs'
3
4
import { fileURLToPath } from 'node:url'
4
5
import { watch } from 'chokidar'
6
+ import defu from 'defu'
7
+
5
8
import { defineNitroModule } from 'nitropack/kit'
6
9
import { dirname , join , resolve } from 'pathe'
7
-
8
10
import { rollupConfig } from './rollup'
9
11
import { relativeWithDot , scanDefs , scanResolvers } from './utils'
10
12
import { clientTypeGeneration , serverTypeGeneration } from './utils/server-type-generation'
@@ -18,6 +20,14 @@ export default defineNitroModule({
18
20
clientDir : '' ,
19
21
}
20
22
23
+ nitro . options . runtimeConfig . graphql = defu ( nitro . options . runtimeConfig . graphql || { } , {
24
+ endpoint : {
25
+ graphql : '/api/graphql' ,
26
+ healthCheck : '/api/graphql/health' ,
27
+ } ,
28
+ playground : true ,
29
+ } as NitroGraphQLOptions )
30
+
21
31
const graphqlBuildDir = resolve ( nitro . options . buildDir , 'graphql' )
22
32
nitro . graphql . buildDir = graphqlBuildDir
23
33
@@ -72,32 +82,36 @@ export default defineNitroModule({
72
82
await serverTypeGeneration ( nitro )
73
83
await clientTypeGeneration ( nitro , nitro . graphql . clientDir )
74
84
75
- // Define the main GraphQL endpoint
76
- const endpoint = '/api/graphql'
77
-
78
85
const runtime = fileURLToPath (
79
86
new URL ( 'routes' , import . meta. url ) ,
80
87
)
81
88
// Main GraphQL endpoint
82
89
nitro . options . handlers . push ( {
83
- route : endpoint ,
90
+ route : nitro . options . runtimeConfig . graphql ?. endpoint ?. graphql || '/api/graphql' ,
84
91
handler : join ( runtime , 'graphql' ) ,
85
92
method : 'get' ,
86
93
} )
87
94
88
95
// Main GraphQL endpoint
89
96
nitro . options . handlers . push ( {
90
- route : endpoint ,
97
+ route : nitro . options . runtimeConfig . graphql ?. endpoint ?. graphql || '/api/graphql' ,
91
98
handler : join ( runtime , 'graphql' ) ,
92
99
method : 'post' ,
93
100
} )
94
101
95
102
nitro . options . handlers . push ( {
96
- route : endpoint ,
103
+ route : nitro . options . runtimeConfig . graphql ?. endpoint ?. graphql || '/api/graphql' ,
97
104
handler : join ( runtime , 'graphql' ) ,
98
105
method : 'options' ,
99
106
} )
100
107
108
+ // Health check endpoint
109
+ nitro . options . handlers . push ( {
110
+ route : nitro . options . runtimeConfig . graphql ?. endpoint ?. healthCheck || '/api/graphql/health' ,
111
+ handler : join ( runtime , 'health' ) ,
112
+ method : 'get' ,
113
+ } )
114
+
101
115
// Auto-import utilities
102
116
if ( nitro . options . imports ) {
103
117
nitro . options . imports . presets . push ( {
0 commit comments