Skip to content

Commit a6e620f

Browse files
committed
Allow legacy names in client schemas.
1 parent 8f936da commit a6e620f

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/utilities/__tests__/buildClientSchema-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,34 @@ describe('Type System: build schema from introspection', () => {
669669
expect(secondIntrospection.data).to.containSubset(newIntrospection);
670670
});
671671

672+
it('builds a schema with legacy names', () => {
673+
const introspection = {
674+
__schema: {
675+
queryType: {
676+
name: 'Query',
677+
},
678+
types: [
679+
{
680+
name: 'Query',
681+
kind: 'OBJECT',
682+
fields: [
683+
{
684+
name: '__badName',
685+
args: [],
686+
type: { name: 'String' },
687+
},
688+
],
689+
interfaces: [],
690+
},
691+
],
692+
},
693+
};
694+
const schema = buildClientSchema(introspection, {
695+
allowedLegacyNames: ['__badName'],
696+
});
697+
expect(schema.__allowedLegacyNames).to.deep.equal(['__badName']);
698+
});
699+
672700
it('builds a schema aware of deprecation', async () => {
673701
const schema = new GraphQLSchema({
674702
query: new GraphQLObjectType({

src/utilities/buildClientSchema.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,7 @@ import type {
6060
IntrospectionNamedTypeRef,
6161
} from './introspectionQuery';
6262

63-
type Options = {|
64-
/**
65-
* When building a schema from a GraphQL service's introspection result, it
66-
* might be safe to assume the schema is valid. Set to true to assume the
67-
* produced schema is valid.
68-
*
69-
* Default: false
70-
*/
71-
assumeValid?: boolean,
72-
|};
63+
import type { GraphQLSchemaValidationOptions } from '../type/schema';
7364

7465
/**
7566
* Build a GraphQLSchema for use by client tools.
@@ -85,7 +76,7 @@ type Options = {|
8576
*/
8677
export function buildClientSchema(
8778
introspection: IntrospectionQuery,
88-
options?: Options,
79+
options?: GraphQLSchemaValidationOptions,
8980
): GraphQLSchema {
9081
// Get the schema from the introspection result.
9182
const schemaIntrospection = introspection.__schema;
@@ -414,5 +405,6 @@ export function buildClientSchema(
414405
types,
415406
directives,
416407
assumeValid: options && options.assumeValid,
408+
allowedLegacyNames: options && options.allowedLegacyNames,
417409
});
418410
}

0 commit comments

Comments
 (0)