From a36ca4b1bd2f25768513b3aa7c4ef32a8d339d3b Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Mon, 23 Jul 2018 14:35:00 +0300 Subject: [PATCH] BREAKING: Remove support for deprecated directive locations Continuation of #1385 --- .../__tests__/buildClientSchema-test.js | 74 +------------------ src/utilities/buildClientSchema.js | 23 +----- 2 files changed, 2 insertions(+), 95 deletions(-) diff --git a/src/utilities/__tests__/buildClientSchema-test.js b/src/utilities/__tests__/buildClientSchema-test.js index 820cbb9580e..b2ae55a04a6 100644 --- a/src/utilities/__tests__/buildClientSchema-test.js +++ b/src/utilities/__tests__/buildClientSchema-test.js @@ -25,8 +25,8 @@ import { GraphQLString, GraphQLBoolean, GraphQLID, + GraphQLDirective, } from '../../'; -import { GraphQLDirective } from '../../type/directives'; // Test property: // Given a server's schema, a client may query that server with introspection, @@ -587,78 +587,6 @@ describe('Type System: build schema from introspection', () => { testSchema(schema); }); - it('builds a schema with legacy directives', () => { - const oldIntrospection = { - __schema: { - // Minimum required schema. - queryType: { - name: 'Simple', - }, - types: [ - { - name: 'Simple', - kind: 'OBJECT', - fields: [ - { - name: 'simple', - args: [], - type: { name: 'Simple' }, - }, - ], - interfaces: [], - }, - ], - // Test old directive introspection results. - directives: [ - { name: 'Old1', args: [], onField: true }, - { name: 'Old2', args: [], onFragment: true }, - { name: 'Old3', args: [], onOperation: true }, - { name: 'Old4', args: [], onField: true, onFragment: true }, - ], - }, - }; - - const clientSchema = buildClientSchema(oldIntrospection); - const secondIntrospection = introspectionFromSchema(clientSchema); - - // New introspection produces correct new format. - expect(secondIntrospection).to.deep.nested.property('__schema.directives', [ - { - name: 'Old1', - description: null, - args: [], - locations: ['FIELD'], - }, - { - name: 'Old2', - description: null, - args: [], - locations: [ - 'FRAGMENT_DEFINITION', - 'FRAGMENT_SPREAD', - 'INLINE_FRAGMENT', - ], - }, - { - name: 'Old3', - description: null, - args: [], - locations: ['QUERY', 'MUTATION', 'SUBSCRIPTION'], - }, - { - name: 'Old4', - description: null, - args: [], - locations: [ - 'FIELD', - 'FRAGMENT_DEFINITION', - 'FRAGMENT_SPREAD', - 'INLINE_FRAGMENT', - ], - }, - ]); - }); - it('builds a schema with legacy names', () => { const introspection = { __schema: { diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index e7e094538aa..66e5053ca64 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -340,27 +340,6 @@ export function buildClientSchema( } function buildDirective(directiveIntrospection) { - // Support deprecated `on****` fields for building `locations`, as this - // is used by GraphiQL which may need to support outdated servers. - const locations = directiveIntrospection.locations - ? directiveIntrospection.locations.slice() - : [].concat( - !directiveIntrospection.onField ? [] : [DirectiveLocation.FIELD], - !directiveIntrospection.onOperation - ? [] - : [ - DirectiveLocation.QUERY, - DirectiveLocation.MUTATION, - DirectiveLocation.SUBSCRIPTION, - ], - !directiveIntrospection.onFragment - ? [] - : [ - DirectiveLocation.FRAGMENT_DEFINITION, - DirectiveLocation.FRAGMENT_SPREAD, - DirectiveLocation.INLINE_FRAGMENT, - ], - ); if (!directiveIntrospection.args) { throw new Error( 'Introspection result missing directive args: ' + @@ -370,7 +349,7 @@ export function buildClientSchema( return new GraphQLDirective({ name: directiveIntrospection.name, description: directiveIntrospection.description, - locations, + locations: directiveIntrospection.locations, args: buildInputValueDefMap(directiveIntrospection.args), }); }