@@ -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 ( / \. (?: g r a p h q l | g q l ) $ / , '-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 ( / \. r e s o l v e r \. t s $ / , '' )
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 ( / \. (?: g r a p h q l | g q l ) $ / , '-schema' )
441+ return chunkName
442+ }
443+
444+ return 'schemas'
445+ } ,
412446 test : / \. (?: g r a p h q l | g q l ) $ / ,
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