Skip to content

Commit c104b7b

Browse files
chore: bump version to 2.0.0-beta.18 in package.json and enhance chunk naming logic in setup
1 parent f1282ae commit c104b7b

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nitro-graphql",
33
"type": "module",
4-
"version": "2.0.0-beta.17",
4+
"version": "2.0.0-beta.18",
55
"packageManager": "[email protected]",
66
"description": "GraphQL integration for Nitro",
77
"license": "MIT",

src/setup.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,27 @@ export async function setupNitroGraphQL(nitro: Nitro) {
372372
if (!rollupConfig.output.inlineDynamicImports) {
373373
// manualChunks for Rollup
374374
rollupConfig.output.manualChunks = (id, meta) => {
375+
// Handle schema files (.graphql, .gql)
375376
if (id.endsWith('.graphql') || id.endsWith('.gql')) {
377+
let graphqlIndex = id.indexOf('server/graphql/')
378+
let baseLength = 'server/graphql/'.length
379+
380+
if (graphqlIndex === -1) {
381+
graphqlIndex = id.indexOf('routes/graphql/')
382+
baseLength = 'routes/graphql/'.length
383+
}
384+
385+
if (graphqlIndex !== -1) {
386+
const relativePath = id.slice(graphqlIndex + baseLength)
387+
// Remove .graphql or .gql extension and add -schema suffix
388+
const chunkName = relativePath.replace(/\.(?:graphql|gql)$/, '-schema')
389+
return chunkName
390+
}
376391
return 'schemas'
377392
}
378393

394+
// Handle resolver files (.resolver.ts)
379395
if (id.endsWith('.resolver.ts')) {
380-
// Extract relative path for per-file chunking
381-
// Support both server/graphql/ (Nitro) and routes/graphql/ (Vite) patterns
382396
let graphqlIndex = id.indexOf('server/graphql/')
383397
let baseLength = 'server/graphql/'.length
384398

@@ -393,7 +407,6 @@ export async function setupNitroGraphQL(nitro: Nitro) {
393407
const chunkName = relativePath.replace(/\.resolver\.ts$/, '')
394408
return chunkName
395409
}
396-
// Fallback if pattern not found
397410
return 'resolvers'
398411
}
399412

@@ -408,7 +421,28 @@ export async function setupNitroGraphQL(nitro: Nitro) {
408421
rollupConfig.output.advancedChunks = {
409422
groups: [
410423
{
411-
name: 'schemas',
424+
// Dynamic chunk naming for schemas
425+
name: (moduleId: string) => {
426+
if (!moduleId.endsWith('.graphql') && !moduleId.endsWith('.gql')) {
427+
return
428+
}
429+
430+
let graphqlIndex = moduleId.indexOf('server/graphql/')
431+
let baseLength = 'server/graphql/'.length
432+
433+
if (graphqlIndex === -1) {
434+
graphqlIndex = moduleId.indexOf('routes/graphql/')
435+
baseLength = 'routes/graphql/'.length
436+
}
437+
438+
if (graphqlIndex !== -1) {
439+
const relativePath = moduleId.slice(graphqlIndex + baseLength)
440+
const chunkName = relativePath.replace(/\.(?:graphql|gql)$/, '-schema')
441+
return chunkName
442+
}
443+
444+
return 'schemas'
445+
},
412446
test: /\.(?:graphql|gql)$/,
413447
},
414448
{
@@ -418,7 +452,6 @@ export async function setupNitroGraphQL(nitro: Nitro) {
418452
return
419453
}
420454

421-
// Extract relative path for per-file chunking
422455
let graphqlIndex = moduleId.indexOf('server/graphql/')
423456
let baseLength = 'server/graphql/'.length
424457

0 commit comments

Comments
 (0)