Skip to content

Commit b900cc6

Browse files
committed
Fix 'extensionASTNodes' for schema extended twice
1 parent 50335ab commit b900cc6

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/utilities/__tests__/extendSchema-test.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,14 +987,25 @@ describe('extendSchema', () => {
987987
hearSomething: String
988988
}
989989
`);
990-
const schema = extendSchema(testSchema, ast);
991-
expect(schema.extensionASTNodes.map(print).join('\n')).to.equal(dedent`
990+
let schema = extendSchema(testSchema, ast);
991+
992+
const secondAST = parse(`
993+
extend schema @foo
994+
995+
directive @foo on SCHEMA
996+
`);
997+
schema = extendSchema(schema, secondAST);
998+
999+
const nodes = schema.extensionASTNodes;
1000+
expect(nodes.map(n => print(n) + '\n').join('')).to.equal(dedent`
9921001
extend schema {
9931002
mutation: Mutation
9941003
}
9951004
extend schema {
9961005
subscription: Subscription
997-
}`);
1006+
}
1007+
extend schema @foo
1008+
`);
9981009
});
9991010

10001011
it('does not allow redefining an existing root type', () => {

src/utilities/extendSchema.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ export function extendSchema(
222222
}
223223
});
224224

225+
const schemaExtensionASTNodes = schemaExtensions
226+
? schema.extensionASTNodes
227+
? schema.extensionASTNodes.concat(schemaExtensions)
228+
: schemaExtensions
229+
: schema.extensionASTNodes;
230+
225231
const types = [
226232
// Iterate through all types, getting the type definition for each, ensuring
227233
// that any type not directly referenced by a field will get created.
@@ -246,7 +252,7 @@ export function extendSchema(
246252
types,
247253
directives: getMergedDirectives(),
248254
astNode: schema.astNode,
249-
extensionASTNodes: schemaExtensions,
255+
extensionASTNodes: schemaExtensionASTNodes,
250256
allowedLegacyNames,
251257
});
252258

0 commit comments

Comments
 (0)