Skip to content

Commit 6160b4d

Browse files
committed
.
1 parent 06bb157 commit 6160b4d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/type/__tests__/validation-test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,23 @@ describe('Type System: A Schema must have Object root types', () => {
431431
},
432432
]);
433433
});
434+
435+
it('rejects a Schema whose directives have empty locations', () => {
436+
const badDirective = new GraphQLDirective({
437+
name: 'BadDirective',
438+
args: {},
439+
locations: [],
440+
});
441+
const schema = new GraphQLSchema({
442+
query: SomeObjectType,
443+
directives: [badDirective],
444+
});
445+
expectJSON(validateSchema(schema)).toDeepEqual([
446+
{
447+
message: 'Directive @BadDirective must include 1 or more locations.',
448+
},
449+
]);
450+
});
434451
});
435452

436453
describe('Type System: Root types must all be different if provided', () => {

src/type/validate.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ function validateDirectives(context: SchemaValidationContext): void {
183183
// Ensure they are named correctly.
184184
validateName(context, directive);
185185

186-
// TODO: Ensure proper locations.
186+
if (directive.locations.length === 0) {
187+
context.reportError(
188+
`Directive @${directive.name} must include 1 or more locations.`,
189+
directive.astNode,
190+
);
191+
}
187192

188193
// Ensure the arguments are valid.
189194
for (const arg of directive.args) {

0 commit comments

Comments
 (0)