Skip to content

Commit 3b0686e

Browse files
feat: register additional GraphQL route handlers using module specifiers
1 parent 88c17e3 commit 3b0686e

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,34 @@
8484
"./subscribe": {
8585
"types": "./dist/subscribe/index.d.mts",
8686
"import": "./dist/subscribe/index.mjs"
87+
},
88+
"./nitro/routes/graphql-yoga": {
89+
"types": "./dist/nitro/routes/graphql-yoga.d.mts",
90+
"import": "./dist/nitro/routes/graphql-yoga.mjs"
91+
},
92+
"./nitro/routes/graphql-yoga-ws": {
93+
"types": "./dist/nitro/routes/graphql-yoga-ws.d.mts",
94+
"import": "./dist/nitro/routes/graphql-yoga-ws.mjs"
95+
},
96+
"./nitro/routes/apollo-server": {
97+
"types": "./dist/nitro/routes/apollo-server.d.mts",
98+
"import": "./dist/nitro/routes/apollo-server.mjs"
99+
},
100+
"./nitro/routes/apollo-server-ws": {
101+
"types": "./dist/nitro/routes/apollo-server-ws.d.mts",
102+
"import": "./dist/nitro/routes/apollo-server-ws.mjs"
103+
},
104+
"./nitro/routes/apollo-sandbox-script": {
105+
"types": "./dist/nitro/routes/apollo-sandbox-script.d.mts",
106+
"import": "./dist/nitro/routes/apollo-sandbox-script.mjs"
107+
},
108+
"./nitro/routes/health": {
109+
"types": "./dist/nitro/routes/health.d.mts",
110+
"import": "./dist/nitro/routes/health.mjs"
111+
},
112+
"./nitro/routes/debug": {
113+
"types": "./dist/nitro/routes/debug.d.mts",
114+
"import": "./dist/nitro/routes/debug.mjs"
87115
}
88116
},
89117
"module": "./dist/index.mjs",

src/nitro/setup/routes.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
*/
44

55
import type { Nitro } from 'nitro/types'
6-
import { fileURLToPath } from 'node:url'
7-
import { join } from 'pathe'
86
import { 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
*/
1315
export 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

Comments
 (0)