From a6cdc83e01f0354c3727bd54dafa4ccaae2a5a04 Mon Sep 17 00:00:00 2001 From: Hemache Adil Date: Fri, 8 Apr 2022 15:07:31 +0000 Subject: [PATCH] feat: allow after build hook to modify the schema e.g. graphql middlewares --- src/builder.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/builder.ts b/src/builder.ts index 8bb592dc..7f736cfb 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -1809,7 +1809,7 @@ export function makeSchemaInternal(config: SchemaConfig) { return returnVal } - const schema = new GraphQLSchema({ + let schema = new GraphQLSchema({ ...extractGraphQLSchemaOptions(config), query: getRootType('query', 'Query'), mutation: getRootType('mutation', 'Mutation'), @@ -1821,7 +1821,9 @@ export function makeSchemaInternal(config: SchemaConfig) { }, }) as NexusGraphQLSchema - onAfterBuildFns.forEach((fn) => fn(schema)) + onAfterBuildFns.forEach((fn) => { + schema = fn(schema) ?? schema + }) return { schema, missingTypes, finalConfig } }