diff --git a/src/utilities/__tests__/buildClientSchema-test.js b/src/utilities/__tests__/buildClientSchema-test.js index 2345cfa00c..4d1961af06 100644 --- a/src/utilities/__tests__/buildClientSchema-test.js +++ b/src/utilities/__tests__/buildClientSchema-test.js @@ -742,6 +742,20 @@ describe('Type System: build schema from introspection', () => { '{ kind: "OBJECT", name: "QueryType", fields: [{ name: "aString", args: [], type: { kind: "SCALAR", name: "String", ofType: null }, isDeprecated: false }] }', ); }); + + it('throws when missing directive locations', () => { + const introspection = { + __schema: { + types: [], + directives: [{ name: 'test', args: [] }], + }, + }; + + expect(() => buildClientSchema(introspection)).to.throw( + 'Introspection result missing directive locations: ' + + '{ name: "test", args: [] }', + ); + }); }); describe('very deep decorators are not supported', () => { diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index fb95422752..eef0c24596 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -344,6 +344,12 @@ export function buildClientSchema( inspect(directiveIntrospection), ); } + if (!directiveIntrospection.locations) { + throw new Error( + 'Introspection result missing directive locations: ' + + inspect(directiveIntrospection), + ); + } return new GraphQLDirective({ name: directiveIntrospection.name, description: directiveIntrospection.description,