Skip to content

Commit

Permalink
buildClientSchema: Throws when missing directive locations (#1507)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Sep 6, 2018
1 parent e36368e commit c8a5792
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/utilities/__tests__/buildClientSchema-test.js
Expand Up @@ -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', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/utilities/buildClientSchema.js
Expand Up @@ -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,
Expand Down

0 comments on commit c8a5792

Please sign in to comment.