Skip to content

Add support for directives on directive definitions - #1206

Merged
leebyron merged 7 commits into
graphql:mainfrom
BoD:directivesOnDirectives2
Jun 4, 2026
Merged

leebyron merged 7 commits into
graphql:mainfrom
BoD:directivesOnDirectives2

Conversation

@BoD

@BoD BoD commented Dec 18, 2025 •

Copy link
Copy Markdown
Contributor

Adds the ability to apply directives to directive definitions and to deprecate directives, with this syntax:

directive @onDirective on DIRECTIVE_DEFINITION

directive @foo @onDirective on OBJECT

directive @baz @deprecated(reason: "...") on OBJECT

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

With @IvanGoncharov's blessing, this PR is a continuation and updated version of #907 which I think can be closed. (There's also prior art in #567).

Motivation

Allow applying directive-exclusive features (e.g. @specifyBy, @deprecated) on directives.

For instance, on Apollo Kotlin we'd like to deprecate some client side directives.

@netlify

netlify Bot commented Dec 18, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for graphql-spec-draft ready!

Name Link
🔨 Latest commit a257894
🔍 Latest deploy log https://app.netlify.com/projects/graphql-spec-draft/deploys/69457e3ea85f4f00083836c9
😎 Deploy Preview https://deploy-preview-1206--graphql-spec-draft.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@BoD

BoD commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

Related graphql-js PR: graphql/graphql-js#4521

@martinbonnin

Copy link
Copy Markdown
Contributor

Another use case: @ignore

@leebyron leebyron added 📄 Draft (RFC 2) RFC Stage 2 (See CONTRIBUTING.md) and removed 💡 Proposal (RFC 1) RFC Stage 1 (See CONTRIBUTING.md) labels Apr 2, 2026
yaacovCR added a commit to graphql/graphql-js that referenced this pull request Apr 24, 2026
Allow directives on directive definitions, based on [this spec PR](graphql/graphql-spec#1206) which introduces this syntax:

```graphql
directive @onDirective on DIRECTIVE_DEFINITION

directive @foo @onDirective on OBJECT

directive @baz @deprecated(reason: "...") on OBJECT

extend directive @quux @deprecated(reason: "...")
```

Co-authored-by: Martin Bonnin <[email protected]>
Co-authored-by: Jerel Miller <[email protected]>
Co-authored-by: Yaacov Rydzinski <[email protected]>
@benjie benjie added the 🚀 Next Stage? This RFC believes it is ready for the next stage label May 7, 2026
Comment thread spec/Section 3 -- Type System.md Resolved

### Directive Extensions

DirectiveExtension : extend directive @ Name Directives[Const]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting: should we be able to extend a directive with new arguments? We can extend a type with new fields that themselves have new arguments.

There is even a special Schema Coordinate for directive arguments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question!

In my opinion, I think yes it would probably make sense in principle to have that ability, even if for consistency alone.
That being said, I would rather tackle this in a separate change later, and based on demand for it.

Curious to know what others think!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would be controversial, but it does make sense to stack into two PRs to make discussion specifically about argument extension more focused.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, GAP-33 assumes that this is already available.

But I think I should iterate on that GAP to make inner extensions use a different syntax because as-is it's not good!

@benjie benjie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for your work on this! I'd like to discuss includeDeprecated at a WG to determine if we might be able to address this e.g. via __schema(includeDeprecated: Boolean! = false) and then remove the need for this new argument, but otherwise I approve 👍

mutationType: __Type
subscriptionType: __Type
directives: [__Directive!]!
directives(includeDeprecated: Boolean! = false): [__Directive!]!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to add this, since I think the whole includeDeprecated dance was a mistake. I think I'd rather see the includeDeprecated argument be itself deprecated across the board, but it defaulting to = false makes this challenging.

@BoD BoD Jun 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I certainly agree about includeDeprecated's benefits being outweighed by its drawbacks. Having it here was about consistency - but maybe if we're planning on deprecating it, we can start by not having it here! Let's discuss this at the next WG.

@leebyron leebyron added 🏁 Accepted (RFC 3) RFC Stage 3 (See CONTRIBUTING.md) and removed 📄 Draft (RFC 2) RFC Stage 2 (See CONTRIBUTING.md) 🚀 Next Stage? This RFC believes it is ready for the next stage labels Jun 4, 2026
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Jun 15, 2026
yaacovCR added a commit to graphql/graphql-js that referenced this pull request Jun 15, 2026
ghostdogpr added a commit to ghostdogpr/caliban that referenced this pull request Nov 15, 2026
* Support directives on directive definitions

Implements graphql/graphql-spec#1206: directives can be applied to
directive definitions, which also makes it possible to deprecate a
directive.

- Parse and render `directive @A @b on ...` and `extend directive @A @b`,
  with the new `DIRECTIVE_DEFINITION` location.
- Validate locations, repeated non-repeatable directives, deprecation
  reasons and cycles through directives and argument types.
- Introspect `__Directive.isDeprecated`, `__Directive.deprecationReason` and
  `__Schema.directives(includeDeprecated:)`, and allow `@deprecated` on
  directive definitions.
- `__Directive` accepts a deprecation and applied directives.
- The tools and gateway introspection clients request the new fields behind
  an opt-in flag, also exposed in codegen and the sbt plugin.
- `RemoteSchema` merges directive extensions, `SchemaComparison` reports
  directive changes on directive definitions and gateway composition keeps
  them.

* Validate repeated @deprecated and compare directive extensions

RemoteSchema turned every @deprecated on a directive definition into the
deprecation flag, so a second one escaped the duplicate check. Only the
first one becomes the flag now.

SchemaComparison compared directive definitions without their extensions,
so `extend directive @A @deprecated` reported no change. Extensions are
now merged first, reusing the merge from RemoteSchema.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏁 Accepted (RFC 3) RFC Stage 3 (See CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants