Skip to content

Commit 3958eae

Browse files
committed
Allow additional legacy names when extending a schema.
1 parent 5f9ff08 commit 3958eae

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/utilities/__tests__/extendSchema-test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,18 +1225,23 @@ describe('extendSchema', () => {
12251225
query: new GraphQLObjectType({
12261226
name: 'Query',
12271227
fields: () => ({
1228-
id: { type: GraphQLID },
1228+
__badName: { type: GraphQLString },
12291229
}),
12301230
}),
12311231
allowedLegacyNames: ['__badName'],
12321232
});
12331233
const ast = parse(`
12341234
extend type Query {
1235-
__badName: String
1235+
__anotherBadName: String
12361236
}
12371237
`);
1238-
const schema = extendSchema(testSchemaWithLegacyNames, ast);
1239-
expect(schema.__allowedLegacyNames).to.deep.equal(['__badName']);
1238+
const schema = extendSchema(testSchemaWithLegacyNames, ast, {
1239+
allowedLegacyNames: ['__anotherBadName'],
1240+
});
1241+
expect(schema.__allowedLegacyNames).to.deep.equal([
1242+
'__badName',
1243+
'__anotherBadName',
1244+
]);
12401245
});
12411246

12421247
describe('does not allow extending a non-object type', () => {

src/utilities/extendSchema.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ type Options = {|
5858

5959
/**
6060
* If provided, the schema will consider fields or types with names included
61-
* in this list valid, even if they do not adhere to the specification's
62-
* schema validation rules.
61+
* in this list valid, in addition to those already allowed on the original
62+
* schema, even if they do not adhere to the specification's schema validation
63+
* rules.
6364
*
6465
* This option is provided to ease adoption and may be removed in a future
6566
* major release.
@@ -255,6 +256,14 @@ export function extendSchema(
255256
types.push(definitionBuilder.buildType(typeName));
256257
});
257258

259+
let allowedLegacyNames = [
260+
...(schema.__allowedLegacyNames || []),
261+
...((options && options.allowedLegacyNames) || []),
262+
];
263+
if (allowedLegacyNames.length === 0) {
264+
allowedLegacyNames = null;
265+
}
266+
258267
// Then produce and return a Schema with these types.
259268
return new GraphQLSchema({
260269
query: queryType,
@@ -263,8 +272,7 @@ export function extendSchema(
263272
types,
264273
directives: getMergedDirectives(),
265274
astNode: schema.astNode,
266-
allowedLegacyNames:
267-
schema.__allowedLegacyNames && schema.__allowedLegacyNames.slice(),
275+
allowedLegacyNames,
268276
});
269277

270278
function appendExtensionToTypeExtensions(

0 commit comments

Comments
 (0)