Repository navigation
parser, validator: accept directives on directive definitions - #515
Merged
StevenACoffman merged 2 commits intoOct 21, 2026
Merged
Conversation
- Parse the directives of a directive definition after its arguments, and the location DIRECTIVE_DEFINITION. - Parse a directive extension into SchemaDocument.DirectiveExtensions. - Merge the directives of each extension into its directive, and refuse an extension of a directive that is not defined. - Validate the directives of a directive at DIRECTIVE_DEFINITION. - Allow @deprecated on a directive definition, and add the introspection fields of deprecated directives to the prelude. - Write both forms in the formatter.
The previous commit hand-edited the generated prelude to add directive deprecation to introspection (__Directive.isDeprecated, __Directive.deprecationReason and __Schema.directives(includeDeprecated:)). The pinned graphql-js has none of these, so the next export would drop them. They would also break gqlgen, whose introspection.Directive and Schema.Directives() have no matching fields or arguments. Drop them; they belong in a separate change coordinated with gqlgen. Keep the DIRECTIVE_DEFINITION location and the @deprecated location that directives on directive definitions need, and have export.js apply them through applyPreludeDeviations so regenerating the prelude preserves them. Also update the singleLocation doc on validateDirectives, which said merged definition-plus-extension lists skip the non-repeatable check; directive definitions are now the exception. Add tests for arguments on a directive extension, extending a builtin directive, and formatting a comment before an extension.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #510 (by @stealth-rklopper), which I could not update. Fixes #506.
This carries the original commit from #510 unchanged (authorship preserved), rebased onto
current master, plus one follow-up commit.
What #510 does
The working draft of the GraphQL spec lets a directive definition take directives, and lets a
schema extend a directive with more of them (graphql/graphql-spec#1206):
DirectiveDefinition.Directives, and the locationDIRECTIVE_DEFINITION.SchemaDocument.DirectiveExtensions.ValidateSchemaDocumentmerges each extension's directives into its directive, and refuses anextension of an undefined directive.
DIRECTIVE_DEFINITION. A non-repeatabledirective may appear once across a directive and its extensions, as graphql-js 17's
UniqueDirectivesPerLocationRulechecks.The grammar matches graphql-js 17 (
parseDirectiveDefinition/parseDirectiveExtension).Follow-up commit
Limit the prelude change to the
DIRECTIVE_DEFINITIONlocation. #510 also addedgraphql-js 17's directive-deprecation introspection to the prelude (
__Directive.isDeprecated,__Directive.deprecationReason,__Schema.directives(includeDeprecated:)). Those break gqlgen:with gqlgen v0.17.95, a minimal project fails to build because
introspection.Directivehas nosuch fields and
Schema.Directives()takes no argument:With this PR the same project generates and builds. The introspection fields should land
together with gqlgen support, in a separate change.
The prelude is generated by
validator/imported/export.jsfrom graphql-js v16.13.2, which hasneither the location nor the
@deprecatedlocation.export.jsnow applies both throughapplyPreludeDeviations, so regenerating the prelude keeps them, and fails loudly if agraphql-js upgrade changes the text they patch.
Also:
singleLocationdoc onvalidateDirectives, which said mergeddefinition-plus-extension lists skip the non-repeatable check; directive definitions are now
the exception.
and formatting a comment before an extension.
The builtin baselines of the formatter change with the prelude.