Skip to content

Add directive-argument opt-in and code-first directive APIs - #9966

Merged
glen-84 merged 1 commit into
mainfrom
gai/directive-argument-opt-in
Jun 22, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/directive-argument-opt-in

Conversation

@glen-84

@glen-84 glen-84 commented Jun 22, 2026

Copy link
Copy Markdown
Member

Summary

  • Directive arguments now participate in opt-in features: @requiresOptIn on a directive argument is validated (rejected on required, non-null arguments without a default), filtered via includeOptIn on __Directive.args, and aggregated into __schema.optInFeatures.
  • New code-first directive APIs: apply directives to directive arguments (IDirectiveArgumentDescriptor.Directive<T>()), mark a directive argument opt-in (.RequiresOptIn(feature)), register directive types via a configure delegate (AddDirectiveType(Action<IDirectiveTypeDescriptor>) on both ISchemaBuilder and IRequestExecutorBuilder), and configure directive arguments inline (IDirectiveTypeDescriptor.Argument(name, Action<IDirectiveArgumentDescriptor>)).
  • Simplified existing AddDirectiveType(new DirectiveType(d => …)) call sites to the new lambda overload.

Test plan

  • Directive-argument opt-in: validation rejects @requiresOptIn on required directive arguments; __Directive.args(includeOptIn:) filtering; optInFeatures aggregation includes directive-argument features.
  • Code-first: .Directive() and .RequiresOptIn() on directive arguments; AddDirectiveType(Action<…>) registration with an argument configurator.
  • Verified the affected suites on net10.0 (Types.Tests, Execution.Tests, Validation.Tests, Types.Mutations.Tests).

Copilot AI review requested due to automatic review settings June 22, 2026 12:59

Copilot AI left a comment

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.

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, and AddDirectiveType(Action<IDirectiveTypeDescriptor>) overloads on both schema and executor builders.
  • Update existing tests/call sites to use the new AddDirectiveType delegate 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.

Comment thread src/HotChocolate/Core/src/Types/Types/Introspection/__Directive.cs
@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall coverage in the gai/directive-argume... branch remains at 49%, unchanged from the main branch.

Show a code coverage summary of the most impacted files.
File main f134fd2 gai/directive-argume... 7f0bf58 +/-
/home/runner/wo...ServerHelper.cs 88% 84% -4%
/home/runner/wo...geDispatcher.cs 77% 75% -2%
/home/runner/wo...tocolHandler.cs 84% 83% -1%
/home/runner/wo...Subscription.cs 90% 92% +2%
/home/runner/wo...ueryExecutor.cs 65% 67% +2%
/home/runner/wo...eiveEndpoint.cs 69% 72% +3%
/home/runner/wo...qlConnection.cs 89% 92% +3%
/home/runner/wo...erMiddleware.cs 89% 100% +11%
/home/runner/wo...tionExecutor.cs 56% 70% +14%
/home/runner/wo...tedDirective.cs 0% 17% +17%

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));
}
}
@glen-84
glen-84 merged commit 30e95e9 into main Jun 22, 2026
277 of 280 checks passed
@glen-84
glen-84 deleted the gai/directive-argument-opt-in branch June 22, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants