From 6f459d0b9be9952a294a62f3b6673fbdfbf8476c Mon Sep 17 00:00:00 2001 From: James Bellenger Date: Fri, 21 Jun 2024 17:49:43 +0300 Subject: [PATCH 1/2] Require non-empty directive locations (#4100) --- src/type/__tests__/validation-test.ts | 17 +++++++++++++++++ src/type/validate.ts | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/type/__tests__/validation-test.ts b/src/type/__tests__/validation-test.ts index c7e3a15449..d5b8773700 100644 --- a/src/type/__tests__/validation-test.ts +++ b/src/type/__tests__/validation-test.ts @@ -425,6 +425,23 @@ describe('Type System: A Schema must have Object root types', () => { }, ]); }); + + it('rejects a Schema whose directives have empty locations', () => { + const badDirective = new GraphQLDirective({ + name: 'BadDirective', + args: {}, + locations: [], + }); + const schema = new GraphQLSchema({ + query: SomeObjectType, + directives: [badDirective], + }); + expectJSON(validateSchema(schema)).toDeepEqual([ + { + message: 'Directive @BadDirective must include 1 or more locations.', + }, + ]); + }); }); describe('Type System: Objects must have fields', () => { diff --git a/src/type/validate.ts b/src/type/validate.ts index 94ef92d05b..56ad63fc64 100644 --- a/src/type/validate.ts +++ b/src/type/validate.ts @@ -172,7 +172,12 @@ function validateDirectives(context: SchemaValidationContext): void { // Ensure they are named correctly. validateName(context, directive); - // TODO: Ensure proper locations. + if (directive.locations.length === 0) { + context.reportError( + `Directive @${directive.name} must include 1 or more locations.`, + directive.astNode, + ); + } // Ensure the arguments are valid. for (const arg of directive.args) { From 20c86657b180899d7223c4264cf9bc0dae0ecf7d Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Thu, 27 Jun 2024 12:59:54 -0400 Subject: [PATCH 2/2] chore: Tag GraphQL JS reviewers team for reviews on PRs (#4130) --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000000..fffb2cb1dc --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @graphql/graphql-js-reviewers