Support @requiresOptIn on directive definitions#9970
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Extends HotChocolate’s opt-in features system to support @requiresOptIn on directive definitions (behind EnableOptInFeatures), including introspection support and aggregation into __schema.optInFeatures.
Changes:
- Allow authoring opt-in requirements on directive definitions across code-first, implementation-first, and schema-first approaches.
- Extend introspection with
__Directive.requiresOptInand__Schema.directives(includeOptIn:)filtering for opt-in directive definitions. - Update tests/snapshots and documentation to cover directive-definition opt-in behavior.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| website/src/docs/hotchocolate/v16/defining-a-schema/versioning.md | Updates opt-in versioning docs to include directive definitions and new introspection entry points. |
| src/HotChocolate/Core/test/Types.Tests/Types/Directives/RequiresOptInDirectiveTests.cs | Adds directive-definition opt-in coverage for code-first / implementation-first / schema-first schema building. |
| src/HotChocolate/Core/test/Types.Tests/Types/Directives/snapshots/RequiresOptInDirectiveTests.BuildSchemaAsync_SchemaFirst_MatchesSnapshot.graphql | Updates schema-first snapshot to include an opt-in directive definition and updated @requiresOptIn locations/description. |
| src/HotChocolate/Core/test/Types.Tests/Types/Directives/snapshots/RequiresOptInDirectiveTests.BuildSchemaAsync_ImplementationFirst_MatchesSnapshot.graphql | Updates implementation-first snapshot for directive-definition opt-in. |
| src/HotChocolate/Core/test/Types.Tests/Types/Directives/snapshots/RequiresOptInDirectiveTests.BuildSchemaAsync_CodeFirst_MatchesSnapshot.graphql | Updates code-first snapshot for directive-definition opt-in. |
| src/HotChocolate/Core/test/Execution.Tests/OptInFeaturesIntrospectionTests.cs | Adds introspection tests for __schema.directives(includeOptIn:) and __Directive.requiresOptIn, and validates feature aggregation. |
| src/HotChocolate/Core/src/Types/Types/Introspection/__Schema.cs | Adds includeOptIn support and filtering to __Schema.directives when opt-in features are enabled. |
| src/HotChocolate/Core/src/Types/Types/Introspection/__Directive.cs | Adds requiresOptIn field to __Directive when opt-in features are enabled. |
| src/HotChocolate/Core/src/Types/Types/Interceptors/OptInFeaturesTypeInterceptor.cs | Aggregates directive-definition opt-in features into the schema’s opt-in feature set. |
| src/HotChocolate/Core/src/Types/Types/Directives/RequiresOptInDirectiveType.cs | Extends @requiresOptIn directive locations to include DIRECTIVE_DEFINITION. |
| src/HotChocolate/Core/src/Types/Types/Directives/RequiresOptInDirectiveExtensions.cs | Adds code-first API for marking directive definitions as opt-in (IDirectiveTypeDescriptor.RequiresOptIn). |
| src/HotChocolate/Core/src/Types/Types/Directives/RequiresOptInAttribute.cs | Enables [RequiresOptIn] usage on directive type classes and configures directive definitions accordingly. |
| src/HotChocolate/Core/src/Types/Properties/TypeResources.resx | Updates localized description text for @requiresOptIn to include directive definitions. |
| src/HotChocolate/Core/src/Types/Properties/TypeResources.Designer.cs | Regenerates strongly-typed resources for the updated @requiresOptIn description. |
Files not reviewed (1)
- src/HotChocolate/Core/src/Types/Properties/TypeResources.Designer.cs: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in the branch remains at 49%, unchanged from the branch. Show a code coverage summary of the most impacted files.
Updated |
This was referenced Jun 26, 2026
Open
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.
Summary
@requiresOptIn, implementing Add directive definition support to opt-in features RFC graphql/graphql-wg#2005 (which addsDIRECTIVE_DEFINITIONas a valid@requiresOptInlocation). All behavior is gated behindEnableOptInFeatures. Follow-up to Add directive-argument opt-in and code-first directive APIs #9966, which added directive-argument opt-in.IDirectiveTypeDescriptor.RequiresOptIn(...)), implementation-first ([RequiresOptIn]on a directive type), and schema-first (@requiresOptInon a directive definition in SDL).__Directive.requiresOptInfield andincludeOptInfiltering on__Schema.directives, so an opt-in directive is hidden unless one of its features is opted into. Directive-definition features are aggregated into__Schema.optInFeaturesalongside the existing element kinds.Test plan
dotnet testforTypes.TestsandExecution.Tests(net10.0), covering the newExecute_IntrospectionOnDirectives*family, the__Directive.requiresOptInanddirectives(includeOptIn:)behavior, and the code-first, implementation-first, and schema-first authoring snapshots.