Skip to content

feat: Support directives on directive definitions - #99

Open
kay-schecker wants to merge 1 commit into
graphql-rust:masterfrom
kay-schecker:feat/directives-on-directive-definitions
Open

kay-schecker wants to merge 1 commit into
graphql-rust:masterfrom
kay-schecker:feat/directives-on-directive-definitions

Conversation

@kay-schecker

Copy link
Copy Markdown

Implements graphql/graphql-spec#1206, which is part of the September 2026 edition of the spec:

directive @onDirective on DIRECTIVE_DEFINITION

directive @foo @onDirective on OBJECT

directive @bar(arg: String) @deprecated(reason: "...") repeatable on FIELD

extend directive @foo @deprecated(reason: "...")

Changes

  • schema::DirectiveDefinition gets a directives field. They are parsed between the arguments and repeatable, following the spec grammar (directive @ Name ArgumentsDefinition? Directives[Const]? repeatable? on DirectiveLocations).
  • New DirectiveLocation::DirectiveDefinition (DIRECTIVE_DEFINITION) in as_str, FromStr and is_query.
  • New schema::DirectiveExtension and Definition::DirectiveExtension for extend directive @name @directive... (spec section "Directive Extensions"). As with the other extensions, at least one directive is required.
  • The schema printer emits all of the above.
  • Tests: round-trip fixtures directive_directives.graphql and extend_directive.graphql, plus grammar unit tests (AST shape, position, and the error for an extension without directives).

The validation rules from the spec (no direct or indirect self-reference) are not part of this crate, which does no validation.

Breaking changes

  • DirectiveDefinition has a new public field, so code that builds it with a struct literal no longer compiles (DirectiveDefinition::new is unaffected).
  • Definition and DirectiveLocation have new variants, so exhaustive matches on them need a new arm.

This needs a minor version bump (0.5.0).

cargo test and cargo fmt --all --check pass.

Implements graphql/graphql-spec#1206 from the September 2026 edition:

- `DirectiveDefinition` gets a `directives` field, parsed between the
  arguments and `repeatable` as in the spec grammar.
- New `DIRECTIVE_DEFINITION` directive location.
- New `extend directive @name @directive` definition
  (`Definition::DirectiveExtension`).
- The schema printer emits all of the above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant