Repository navigation
Add directive-argument opt-in and code-first directive APIs - #9966
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands HotChocolate’s directive model by bringing directive arguments into the existing opt-in feature system (@requiresOptIn) and by adding code-first APIs for defining directive types and configuring directive arguments more fluently.
Changes:
- Extend opt-in feature handling to directive arguments (validation, introspection filtering via
__Directive.args(includeOptIn:), and aggregation into__schema.optInFeatures). - Add code-first directive APIs: directive-argument configuration via
IDirectiveTypeDescriptor.Argument(name, Action<...>), directive application on directive arguments, andAddDirectiveType(Action<IDirectiveTypeDescriptor>)overloads on both schema and executor builders. - Update existing tests/call sites to use the new
AddDirectiveTypedelegate overloads and add coverage for directive-argument opt-in behavior.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Core/test/Validation.Tests/ValidationUtils.cs | Updates test helper to use the new AddDirectiveType(Action<...>) overload. |
| src/HotChocolate/Core/test/Types.Tests/Types/Interceptors/FlagEnumInterceptorTests.cs | Migrates directive type registration to the new lambda-based overload. |
| src/HotChocolate/Core/test/Types.Tests/Types/EnumTypeTests.cs | Migrates directive type registration to the new lambda-based overload in multiple tests. |
| src/HotChocolate/Core/test/Types.Tests/Types/DirectiveTypeTests.cs | Migrates directive type registration and adds a test for applying directives to directive arguments. |
| src/HotChocolate/Core/test/Types.Tests/Types/Directives/RequiresOptInDirectiveTests.cs | Adds code-first opt-in features on directive arguments for snapshot coverage. |
| src/HotChocolate/Core/test/Types.Tests/Types/Directives/snapshots/RequiresOptInDirectiveTests.BuildSchemaAsync_CodeFirst_MatchesSnapshot.graphql | Updates snapshot to include directive-argument @requiresOptIn. |
| src/HotChocolate/Core/test/Types.Tests/Extensions/SchemaBuilderExtensions.Types.Tests.cs | Adds test coverage for AddDirectiveType(Action<...>) and adjusts null overload ambiguity. |
| src/HotChocolate/Core/test/Types.Tests/Configuration/Validation/RequiresOptInValidation.cs | Adds SDL validation tests for @requiresOptIn on directive arguments. |
| src/HotChocolate/Core/test/Types.Tests/Configuration/Validation/snapshots/RequiresOptInValidation.Must_Not_Appear_On_Required_Directive_Argument.snap | Adds snapshot for the new validation error. |
| src/HotChocolate/Core/test/Types.Tests/Configuration/TypeTrimmerTests.cs | Migrates directive type registration to the new lambda-based overload. |
| src/HotChocolate/Core/test/Types.Mutations.Tests/AnnotationBasedMutations.cs | Migrates directive type registration to the new lambda-based overload. |
| src/HotChocolate/Core/test/Execution.Tests/OptInFeaturesIntrospectionTests.cs | Adds directive-argument opt-in introspection tests and ensures schema opt-in aggregation includes directive-arg features. |
| src/HotChocolate/Core/test/Execution.Tests/IntrospectionTests.cs | Migrates directive type registration to the new lambda-based overload. |
| src/HotChocolate/Core/src/Types/Utilities/ErrorHelper.cs | Adds a schema error factory for invalid opt-in usage on required directive arguments. |
| src/HotChocolate/Core/src/Types/Types/Introspection/__Directive.cs | Adds includeOptIn filtering to __Directive.args when opt-in features are enabled. |
| src/HotChocolate/Core/src/Types/Types/Interceptors/OptInFeaturesTypeInterceptor.cs | Aggregates opt-in features from directive arguments and supports SDL @requiresOptIn parsing. |
| src/HotChocolate/Core/src/Types/Types/Directives/RequiresOptInDirectiveExtensions.cs | Adds .RequiresOptIn() support for IDirectiveArgumentDescriptor. |
| src/HotChocolate/Core/src/Types/Types/Descriptors/DirectiveTypeDescriptor.cs | Adds Argument(name, Action<...>) convenience overload for inline directive-argument configuration. |
| src/HotChocolate/Core/src/Types/Types/Descriptors/DirectiveArgumentDescriptor.cs | Adds fluent directive-application APIs returning IDirectiveArgumentDescriptor. |
| src/HotChocolate/Core/src/Types/Types/Descriptors/Contracts/IDirectiveTypeDescriptor.cs | Adds Argument(name, Action<...>) to the public contract. |
| src/HotChocolate/Core/src/Types/Types/Descriptors/Contracts/IDirectiveArgumentDescriptor.cs | Adds directive-application APIs (Directive(...)) to the public contract. |
| src/HotChocolate/Core/src/Types/Extensions/SchemaBuilderExtensions.Types.cs | Adds ISchemaBuilder.AddDirectiveType(Action<...>) overload. |
| src/HotChocolate/Core/src/Types/Execution/DependencyInjection/SchemaRequestExecutorBuilderExtensions.Types.cs | Adds IRequestExecutorBuilder.AddDirectiveType(Action<...>) overload. |
| src/HotChocolate/Core/src/Types/Configuration/Validation/RequiresOptInValidationRule.cs | Validates @requiresOptIn constraints for directive arguments. |
💡 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 Show a code coverage summary of the most impacted files.
Code Coverage is in Public Preview. Learn more and provide us with your feedback. |
Comment on lines
+61
to
+71
| foreach (var argument in directive.Arguments) | ||
| { | ||
| if (argument.Type.IsNonNullType() | ||
| && argument.DefaultValue is null | ||
| && argument.Directives.Any(d => d.Definition is RequiresOptInDirectiveType)) | ||
| { | ||
| errors.Add(RequiresOptInOnRequiredDirectiveArgument( | ||
| directive, | ||
| argument)); | ||
| } | ||
| } |
This was referenced Jun 26, 2026
Closed
This was referenced Jul 5, 2026
This was referenced Jul 13, 2026
This was referenced Aug 27, 2026
Closed
This was referenced Sep 7, 2026
This was referenced Sep 17, 2026
This was referenced Sep 28, 2026
This was referenced Oct 5, 2026
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
@requiresOptInon a directive argument is validated (rejected on required, non-null arguments without a default), filtered viaincludeOptInon__Directive.args, and aggregated into__schema.optInFeatures.IDirectiveArgumentDescriptor.Directive<T>()), mark a directive argument opt-in (.RequiresOptIn(feature)), register directive types via a configure delegate (AddDirectiveType(Action<IDirectiveTypeDescriptor>)on bothISchemaBuilderandIRequestExecutorBuilder), and configure directive arguments inline (IDirectiveTypeDescriptor.Argument(name, Action<IDirectiveArgumentDescriptor>)).AddDirectiveType(new DirectiveType(d => …))call sites to the new lambda overload.Test plan
@requiresOptInon required directive arguments;__Directive.args(includeOptIn:)filtering;optInFeaturesaggregation includes directive-argument features..Directive()and.RequiresOptIn()on directive arguments;AddDirectiveType(Action<…>)registration with an argument configurator.