Skip to content

Commit

Permalink
Maintain allowed legacy names when extending a schema. (#1226)
Browse files Browse the repository at this point in the history
* Maintain allowed legacy names when extending a schema.

* .slice() is a more canonical copy

* Update extendSchema-test.js

* Move schema local to test
  • Loading branch information
alloy authored and leebyron committed Feb 7, 2018
1 parent 312daa5 commit 4b96a86
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/utilities/__tests__/extendSchema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,25 @@ 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(testSchemaWithLegacyNames, ast);
expect(schema.__allowedLegacyNames).to.deep.equal(['__badName']);
});

describe('does not allow extending a non-object type', () => {
it('not an interface', () => {
const ast = parse(`
Expand Down
2 changes: 2 additions & 0 deletions src/utilities/extendSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ export function extendSchema(
types,
directives: getMergedDirectives(),
astNode: schema.astNode,
allowedLegacyNames:
schema.__allowedLegacyNames && schema.__allowedLegacyNames.slice(),
});

// Below are functions used for producing this schema that have closed over
Expand Down

0 comments on commit 4b96a86

Please sign in to comment.