From 5b19c8289d2a8a8c58ebfc2bcb25b5f2cf765c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Wed, 7 Feb 2018 17:10:47 +0100 Subject: [PATCH 1/4] Maintain allowed legacy names when extending a schema. --- src/utilities/__tests__/extendSchema-test.js | 11 +++++++++++ src/utilities/extendSchema.js | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/utilities/__tests__/extendSchema-test.js b/src/utilities/__tests__/extendSchema-test.js index 31d32d7077..3becd7b3ca 100644 --- a/src/utilities/__tests__/extendSchema-test.js +++ b/src/utilities/__tests__/extendSchema-test.js @@ -90,6 +90,7 @@ const testSchema = new GraphQLSchema({ }), }), types: [FooType, BarType], + allowedLegacyNames: ['__badName'], }); describe('extendSchema', () => { @@ -994,6 +995,16 @@ describe('extendSchema', () => { ); }); + it('maintains configuration of the original schema object', () => { + const ast = parse(` + extend type Query { + __badName: String + } + `); + const schema = extendSchema(testSchema, ast); + expect(schema.__allowedLegacyNames).to.eql(['__badName']); + }); + describe('does not allow extending a non-object type', () => { it('not an interface', () => { const ast = parse(` diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index f064894c17..8a793687c1 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -230,6 +230,8 @@ export function extendSchema( types, directives: getMergedDirectives(), astNode: schema.astNode, + allowedLegacyNames: + schema.__allowedLegacyNames && schema.__allowedLegacyNames.slice(0), }); // Below are functions used for producing this schema that have closed over From 653083fa69cddf34263b1862984f88652674eebe Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Wed, 7 Feb 2018 10:43:32 -0800 Subject: [PATCH 2/4] .slice() is a more canonical copy --- src/utilities/extendSchema.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index 8a793687c1..4ef8deabe1 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -231,7 +231,7 @@ export function extendSchema( directives: getMergedDirectives(), astNode: schema.astNode, allowedLegacyNames: - schema.__allowedLegacyNames && schema.__allowedLegacyNames.slice(0), + schema.__allowedLegacyNames && schema.__allowedLegacyNames.slice(), }); // Below are functions used for producing this schema that have closed over From dc34d193f50f8748f75486b22392d3ec4037068d Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Wed, 7 Feb 2018 10:44:08 -0800 Subject: [PATCH 3/4] Update extendSchema-test.js --- src/utilities/__tests__/extendSchema-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities/__tests__/extendSchema-test.js b/src/utilities/__tests__/extendSchema-test.js index 3becd7b3ca..d4f591b140 100644 --- a/src/utilities/__tests__/extendSchema-test.js +++ b/src/utilities/__tests__/extendSchema-test.js @@ -1002,7 +1002,7 @@ describe('extendSchema', () => { } `); const schema = extendSchema(testSchema, ast); - expect(schema.__allowedLegacyNames).to.eql(['__badName']); + expect(schema.__allowedLegacyNames).to.deep.equal(['__badName']); }); describe('does not allow extending a non-object type', () => { From 02577b7e57aa1db292554fd6193815f2fa8542f5 Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Wed, 7 Feb 2018 10:46:24 -0800 Subject: [PATCH 4/4] Move schema local to test --- src/utilities/__tests__/extendSchema-test.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utilities/__tests__/extendSchema-test.js b/src/utilities/__tests__/extendSchema-test.js index d4f591b140..6a971b7f3d 100644 --- a/src/utilities/__tests__/extendSchema-test.js +++ b/src/utilities/__tests__/extendSchema-test.js @@ -90,7 +90,6 @@ const testSchema = new GraphQLSchema({ }), }), types: [FooType, BarType], - allowedLegacyNames: ['__badName'], }); describe('extendSchema', () => { @@ -996,12 +995,21 @@ describe('extendSchema', () => { }); it('maintains configuration of the original schema object', () => { + const testSchemaWithLegacyNames = new GraphQLSchema({ + query: new GraphQLObjectType({ + name: 'Query', + fields: () => ({ + id: { type: GraphQLID }, + }), + }), + allowedLegacyNames: ['__badName'], + }); const ast = parse(` extend type Query { __badName: String } `); - const schema = extendSchema(testSchema, ast); + const schema = extendSchema(testSchemaWithLegacyNames, ast); expect(schema.__allowedLegacyNames).to.deep.equal(['__badName']); });