File tree Expand file tree Collapse file tree 6 files changed +23
-4
lines changed
playground-nuxt/server/graphql
playground/server/graphql Expand file tree Collapse file tree 6 files changed +23
-4
lines changed File renamed without changes.
Original file line number Diff line number Diff line change 22export default defineGraphQLConfig ( {
33 // Custom context enhancer - adds additional properties to GraphQL context
44
5+ graphiql : true ,
56 // Additional yoga options can be added here
67 // See: https://the-guild.dev/graphql/yoga-server/docs
78} )
Original file line number Diff line number Diff line change @@ -3,13 +3,14 @@ import type { Nitro } from 'nitropack'
33import { readFile } from 'node:fs/promises'
44import { parse } from 'graphql'
55import { genImport } from 'knitwork'
6+ import { resolve } from 'pathe'
67import { getImportId , scanGraphql } from './utils'
78import { serverTypeGeneration } from './utils/server-type-generation'
89
910export async function rollupConfig ( app : Nitro ) {
1011 virtualDefs ( app )
1112 virtualResolvers ( app )
12-
13+ getGraphQLConfig ( app )
1314 app . hooks . hook ( 'rollup:before' , ( nitro , rollupConfig ) => {
1415 rollupConfig . plugins = rollupConfig . plugins || [ ]
1516 const {
@@ -154,3 +155,15 @@ export function virtualResolvers(app: Nitro) {
154155 return code
155156 }
156157}
158+
159+ export function getGraphQLConfig ( app : Nitro ) {
160+ const configPath = resolve ( app . graphql . serverDir , 'config.ts' )
161+
162+ app . options . virtual ??= { }
163+ app . options . virtual [ '#nitro-internal-virtual/graphql-config' ] = ( ) => {
164+ return `import config from '${ configPath } '
165+ const importedConfig = config
166+ export { importedConfig }
167+ `
168+ }
169+ }
Original file line number Diff line number Diff line change 11import type { YogaServerInstance } from 'graphql-yoga'
2- import { defs } from '#nitro-internal-virtual/server-defs '
2+ import { importedConfig } from '#nitro-internal-virtual/graphql-config '
33
4+ import { defs } from '#nitro-internal-virtual/server-defs'
45import { resolvers } from '#nitro-internal-virtual/server-resolvers'
6+
57import { mergeResolvers , mergeTypeDefs } from '@graphql-tools/merge'
8+ import defu from 'defu'
69import { createSchema , createYoga } from 'graphql-yoga'
710import { defineEventHandler , toWebRequest } from 'h3'
811// TODO: https://github.com/nitrojs/nitro/issues/3403 if used import this error.
@@ -57,12 +60,12 @@ export default defineEventHandler(async (event) => {
5760 if ( ! yoga ) {
5861 const schema = createMergedSchema ( )
5962 // Yoga instance'ı henüz oluşturulmadıysa, oluştur
60- yoga = createYoga ( {
63+ yoga = createYoga ( defu ( {
6164 schema,
6265 graphqlEndpoint : '/api/graphql' ,
6366 landingPage : false ,
6467 renderGraphiQL : ( ) => apolloSandboxHtml ,
65- } )
68+ } , importedConfig ) )
6669 }
6770 const request = toWebRequest ( event )
6871 const response = await yoga . handleRequest ( request , event as any )
Original file line number Diff line number Diff line change 1+ export const importedConfig : any = { }
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ export default defineConfig({
3535 'h3' ,
3636 '#nitro-internal-virtual/server-defs' ,
3737 '#nitro-internal-virtual/server-resolvers' ,
38+ '#nitro-internal-virtual/graphql-config' ,
3839 '@nuxt/kit' ,
3940 '@nuxt/schema' ,
4041 '@apollo/server' ,
You can’t perform that action at this time.
0 commit comments