Skip to content

Commit

Permalink
BREAKING: Remove support for deprecated directive locations (#1429)
Browse files Browse the repository at this point in the history
Continuation of #1385
  • Loading branch information
IvanGoncharov authored and mjmahone committed Jul 26, 2018
1 parent fec220b commit 183c532
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 97 deletions.
74 changes: 1 addition & 73 deletions src/utilities/__tests__/buildClientSchema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down
25 changes: 1 addition & 24 deletions src/utilities/buildClientSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { valueFromAST } from './valueFromAST';
import { parseValue } from '../language/parser';
import { GraphQLSchema } from '../type/schema';

import { DirectiveLocation } from '../language/directiveLocation';

import {
isInputType,
isOutputType,
Expand Down Expand Up @@ -340,27 +338,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: ' +
Expand All @@ -370,7 +347,7 @@ export function buildClientSchema(
return new GraphQLDirective({
name: directiveIntrospection.name,
description: directiveIntrospection.description,
locations,
locations: directiveIntrospection.locations.slice(),
args: buildInputValueDefMap(directiveIntrospection.args),
});
}
Expand Down

0 comments on commit 183c532

Please sign in to comment.