Repository navigation
Add directive definition support to opt-in features RFC #2005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
martinbonnin
merged 1 commit into
graphql:main
from
glen-84:gai/optin-features-directive-support
Jun 18, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,14 +55,15 @@ It is proposed to add an `@requiresOptIn` directive to the specification: | |
|
|
||
| ```graphql | ||
| """ | ||
| Indicates that the given field, argument, input field or enum value requires | ||
| giving explicit consent before being used. | ||
| Indicates that the given field, argument, input field, enum value, or | ||
| directive definition requires giving explicit consent before being used. | ||
| """ | ||
| directive @requiresOptIn(feature: String!) repeatable | ||
| on FIELD_DEFINITION | ||
| | ARGUMENT_DEFINITION | ||
| | INPUT_FIELD_DEFINITION | ||
| | ENUM_VALUE | ||
| | DIRECTIVE_DEFINITION | ||
| ``` | ||
|
|
||
| The `optIn` directive can then be used in the schema. For an example, to signal an experimental field: | ||
|
|
@@ -77,12 +78,20 @@ type Session { | |
| } | ||
| ``` | ||
|
|
||
| A directive definition can also require opt-in, gating use of the directive itself: | ||
|
|
||
| ```graphql | ||
| directive @deploymentMetadata | ||
| @requiresOptIn(feature: "experimentalDeploymentApi") | ||
| on FIELD_DEFINITION | ||
| ``` | ||
|
|
||
| ### Introspection | ||
|
|
||
| > This section is a proposal based on the current introspection mechanism. A more global mechanism ( | ||
| > see [#300](https://github.com/graphql/graphql-spec/issues/300)) would make it obsolete | ||
|
|
||
| `@requiresOptIn` features should be hidden from introspection by default and include if `includeRequiresOptIn` contains the | ||
| `@requiresOptIn` features should be hidden from introspection by default and included if `includeRequiresOptIn` contains the | ||
| given feature: | ||
|
|
||
| ```graphql | ||
|
|
@@ -93,11 +102,11 @@ type __Type { | |
| # [...] other fields omitted for clarity | ||
|
|
||
| # includeRequiresOptIn is a list of features to include | ||
| fields(includeDeprecated: Boolean = false, includeRequiresOptIn: [String!]): [__Field!] | ||
| fields(includeDeprecated: Boolean! = false, includeRequiresOptIn: [String!]): [__Field!] | ||
| } | ||
| ``` | ||
|
|
||
| Tools can get a list of `@requiresOptIn` features required to use a field (or input field, argument, enum value) | ||
| Tools can get a list of `@requiresOptIn` features required to use a field (or input field, argument, enum value, or directive definition) | ||
| using `requiresOptIn`: | ||
|
|
||
| ```graphql | ||
|
|
@@ -109,7 +118,7 @@ type __Field { | |
|
|
||
| # list of @requiresOptIn features required to use this field | ||
| requiresOptIn: [String!] | ||
| args(includeDeprecated: Boolean = false, includeRequiresOptIn: [String!]): [__InputValue!]! | ||
| args(includeDeprecated: Boolean! = false, includeRequiresOptIn: [String!]): [__InputValue!]! | ||
| } | ||
| ``` | ||
|
|
||
|
|
@@ -151,8 +160,7 @@ Cons: | |
|
|
||
| ### marker directives | ||
|
|
||
| The spec defines a directive named @requiresOptIn (and in doing so introduces the need to be able to apply directives to | ||
| directive definitions) | ||
| The spec defines a directive named @requiresOptIn: | ||
|
|
||
| ```graphql | ||
| directive @requiresOptIn on DIRECTIVE_DEFINITION | ||
|
|
@@ -162,7 +170,7 @@ Services create a directive for each distinct opt-in feature they want in their | |
|
|
||
| ```graphql | ||
| # optIn usage defines @experimentalDeploymentApi as an opt-in marker | ||
| directive @experimentalDeploymentApi on FIELD_DEFINITION @requiresOptIn | ||
| directive @experimentalDeploymentApi @requiresOptIn on FIELD_DEFINITION | ||
|
|
||
| type Query { | ||
| deployment: Deployment @experimentalDeploymentApi | ||
|
|
@@ -172,7 +180,7 @@ enum WorkspaceKind { | |
| CROSS_PROJECT | ||
| CROSS_COMPANY | ||
| } | ||
| directive @workspaces(kind: WorkspaceKind) on FIELD_DEFINITION @requiresOptIn | ||
| directive @workspaces(kind: WorkspaceKind) @requiresOptIn on FIELD_DEFINITION | ||
|
|
||
| type Deployment { | ||
| workspaces: [Workspace] @workspaces(kind: CROSS_COMPANY) | ||
|
|
@@ -187,7 +195,6 @@ Pros: | |
| Cons: | ||
|
|
||
| * more complex | ||
| * requires a grammar change | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
|
|
||
| ## 🪵 Decision Log | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 👍