Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain allowed legacy names when extending a schema. #1226

Merged
merged 4 commits into from
Feb 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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