33 */
44
55import type { Nitro } from 'nitro/types'
6- import { fileURLToPath } from 'node:url'
7- import { join } from 'pathe'
86import { ENDPOINT_DEBUG , GRAPHQL_HTTP_METHODS } from '../../core/constants'
97
108/**
119 * Register GraphQL route handlers
10+ *
11+ * Uses module specifiers instead of filesystem paths for route handlers.
12+ * This ensures handlers are resolved correctly both in local development
13+ * (monorepo symlink) and in CI/production (installed from npm).
1214 */
1315export function registerRouteHandlers ( nitro : Nitro ) : void {
14- const runtime = fileURLToPath ( new URL ( '../routes' , import . meta. url ) )
1516 const framework = nitro . options . graphql ?. framework
1617 const subscriptions = nitro . options . graphql ?. subscriptions
1718 const endpoint = nitro . options . runtimeConfig . graphql ?. endpoint ?. graphql || '/api/graphql'
@@ -21,15 +22,15 @@ export function registerRouteHandlers(nitro: Nitro): void {
2122 for ( const method of GRAPHQL_HTTP_METHODS ) {
2223 nitro . options . handlers . push ( {
2324 route : endpoint ,
24- handler : join ( runtime , ' graphql-yoga') ,
25+ handler : 'nitro- graphql/nitro/routes/graphql -yoga',
2526 method,
2627 } )
2728 }
2829
2930 // Apollo Sandbox script proxy (cacheable)
3031 nitro . options . handlers . push ( {
3132 route : `${ endpoint } /sandbox.js` ,
32- handler : join ( runtime , ' apollo-sandbox-script') ,
33+ handler : 'nitro-graphql/nitro/routes/ apollo-sandbox-script',
3334 method : 'GET' ,
3435 } )
3536
@@ -39,7 +40,7 @@ export function registerRouteHandlers(nitro: Nitro): void {
3940 const wsPath = subscriptions . websocket ?. path || `${ endpoint } /ws`
4041 nitro . options . handlers . push ( {
4142 route : wsPath ,
42- handler : join ( runtime , ' graphql-yoga-ws') ,
43+ handler : 'nitro- graphql/nitro/routes/graphql -yoga-ws',
4344 } )
4445 }
4546 }
@@ -48,7 +49,7 @@ export function registerRouteHandlers(nitro: Nitro): void {
4849 for ( const method of GRAPHQL_HTTP_METHODS ) {
4950 nitro . options . handlers . push ( {
5051 route : endpoint ,
51- handler : join ( runtime , ' apollo-server') ,
52+ handler : 'nitro-graphql/nitro/routes/ apollo-server',
5253 method,
5354 } )
5455 }
@@ -59,23 +60,23 @@ export function registerRouteHandlers(nitro: Nitro): void {
5960 const wsPath = subscriptions . websocket ?. path || `${ endpoint } /ws`
6061 nitro . options . handlers . push ( {
6162 route : wsPath ,
62- handler : join ( runtime , ' apollo-server-ws') ,
63+ handler : 'nitro-graphql/nitro/routes/ apollo-server-ws',
6364 } )
6465 }
6566 }
6667
6768 // Health check endpoint
6869 nitro . options . handlers . push ( {
6970 route : nitro . options . runtimeConfig . graphql ?. endpoint ?. healthCheck || '/api/graphql/health' ,
70- handler : join ( runtime , ' health') ,
71+ handler : 'nitro-graphql/nitro/routes/ health',
7172 method : 'GET' ,
7273 } )
7374
7475 // Debug endpoint (development only)
7576 if ( nitro . options . dev ) {
7677 nitro . options . handlers . push ( {
7778 route : ENDPOINT_DEBUG ,
78- handler : join ( runtime , ' debug') ,
79+ handler : 'nitro-graphql/nitro/routes/ debug',
7980 method : 'GET' ,
8081 } )
8182 }
0 commit comments