11import type { Nitro } from 'nitropack/types'
2+ import type { NitroGraphQLOptions } from './types'
23import { writeFileSync } from 'node:fs'
34import { fileURLToPath } from 'node:url'
45import { watch } from 'chokidar'
6+ import defu from 'defu'
7+
58import { defineNitroModule } from 'nitropack/kit'
69import { dirname , join , resolve } from 'pathe'
7-
810import { rollupConfig } from './rollup'
911import { relativeWithDot , scanDefs , scanResolvers } from './utils'
1012import { clientTypeGeneration , serverTypeGeneration } from './utils/server-type-generation'
@@ -18,6 +20,14 @@ export default defineNitroModule({
1820 clientDir : '' ,
1921 }
2022
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+
2131 const graphqlBuildDir = resolve ( nitro . options . buildDir , 'graphql' )
2232 nitro . graphql . buildDir = graphqlBuildDir
2333
@@ -72,32 +82,36 @@ export default defineNitroModule({
7282 await serverTypeGeneration ( nitro )
7383 await clientTypeGeneration ( nitro , nitro . graphql . clientDir )
7484
75- // Define the main GraphQL endpoint
76- const endpoint = '/api/graphql'
77-
7885 const runtime = fileURLToPath (
7986 new URL ( 'routes' , import . meta. url ) ,
8087 )
8188 // Main GraphQL endpoint
8289 nitro . options . handlers . push ( {
83- route : endpoint ,
90+ route : nitro . options . runtimeConfig . graphql ?. endpoint ?. graphql || '/api/graphql' ,
8491 handler : join ( runtime , 'graphql' ) ,
8592 method : 'get' ,
8693 } )
8794
8895 // Main GraphQL endpoint
8996 nitro . options . handlers . push ( {
90- route : endpoint ,
97+ route : nitro . options . runtimeConfig . graphql ?. endpoint ?. graphql || '/api/graphql' ,
9198 handler : join ( runtime , 'graphql' ) ,
9299 method : 'post' ,
93100 } )
94101
95102 nitro . options . handlers . push ( {
96- route : endpoint ,
103+ route : nitro . options . runtimeConfig . graphql ?. endpoint ?. graphql || '/api/graphql' ,
97104 handler : join ( runtime , 'graphql' ) ,
98105 method : 'options' ,
99106 } )
100107
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+
101115 // Auto-import utilities
102116 if ( nitro . options . imports ) {
103117 nitro . options . imports . presets . push ( {
0 commit comments