-
-
Notifications
You must be signed in to change notification settings - Fork 799
Added opt-in features #7652
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
Open
glen-84
wants to merge
22
commits into
main
Choose a base branch
from
gai/opt-in-features
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Added opt-in features #7652
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8908d59
Added opt-in features
glen-84 f270649
Added OptInFeatureStability extension method to IRequestExecutorBuilder
glen-84 f01f415
Enforced valid GraphQL names for features and stability
glen-84 3d38ab7
Merge branch 'main' into gai/opt-in-features
michaelstaib 8e5e2d1
Merge branch 'main' into gai/opt-in-features
michaelstaib 3d79b77
Merge branch 'main' into gai/opt-in-features
glen-84 4a8b57c
Merge branch 'main' into gai/opt-in-features
glen-84 2f31b5a
Merge branch 'main' into gai/opt-in-features
glen-84 f7eaab4
Merge branch 'main' into gai/opt-in-features
glen-84 de8f95b
Merge branch 'main' into gai/opt-in-features
glen-84 dc2390d
Fixed error
glen-84 16de3ee
Merge branch 'main' into gai/opt-in-features
glen-84 631d54b
Merge branch 'main' into gai/opt-in-features
glen-84 4b9ec74
Merge branch 'main' into gai/opt-in-features
glen-84 dbb6221
Fixed analyzer errors
glen-84 2ce9fb9
Merge branch 'main' into gai/opt-in-features
glen-84 2ea18e0
Merge branch 'main' into gai/opt-in-features
michaelstaib 47ff057
Merge 2ea18e07ce1b66d67f45ff51d14693260a62f13c into e07970c4422156975…
glen-84 5ec99d9
Update performance data [skip ci]
github-actions[bot] 430b8aa
Merge branch 'main' into gai/opt-in-features
michaelstaib d80a6a9
Merge 430b8aad66691a3d340c903b8c8db8e6cf96aea5 into d0b6d5ee1dfbd29c3…
glen-84 6ea9e8b
Update performance data [skip ci]
github-actions[bot] 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
67 changes: 67 additions & 0 deletions
67
src/HotChocolate/Core/src/Types/Configuration/Validation/RequiresOptInValidationRule.cs
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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| using HotChocolate.Types; | ||
| using HotChocolate.Types.Descriptors; | ||
| using static HotChocolate.Utilities.ErrorHelper; | ||
|
|
||
| namespace HotChocolate.Configuration.Validation; | ||
|
|
||
| internal sealed class RequiresOptInValidationRule : ISchemaValidationRule | ||
| { | ||
| public void Validate( | ||
| IDescriptorContext context, | ||
| ISchema schema, | ||
| ICollection<ISchemaError> errors) | ||
| { | ||
| if (!context.Options.EnableOptInFeatures) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| foreach (var type in schema.Types) | ||
| { | ||
| switch (type) | ||
| { | ||
| case IInputObjectType inputObjectType: | ||
| foreach (var field in inputObjectType.Fields) | ||
| { | ||
| if (field.Type.IsNonNullType() && field.DefaultValue is null) | ||
| { | ||
| var requiresOptInDirectives = field.Directives | ||
| .Where(d => d.Type is RequiresOptInDirectiveType); | ||
|
|
||
| foreach (var _ in requiresOptInDirectives) | ||
| { | ||
| errors.Add(RequiresOptInOnRequiredInputField( | ||
| inputObjectType, | ||
| field)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| break; | ||
|
|
||
| case IObjectType objectType: | ||
| foreach (var field in objectType.Fields) | ||
| { | ||
| foreach (var argument in field.Arguments) | ||
| { | ||
| if (argument.Type.IsNonNullType() && argument.DefaultValue is null) | ||
| { | ||
| var requiresOptInDirectives = argument.Directives | ||
| .Where(d => d.Type is RequiresOptInDirectiveType); | ||
|
|
||
| foreach (var _ in requiresOptInDirectives) | ||
| { | ||
| errors.Add(RequiresOptInOnRequiredArgument( | ||
| objectType, | ||
| field, | ||
| argument)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
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
81 changes: 81 additions & 0 deletions
81
src/HotChocolate/Core/src/Types/Properties/TypeResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
37 changes: 37 additions & 0 deletions
37
src/HotChocolate/Core/src/Types/Types/Directives/OptInFeatureStabilityDirective.cs
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| namespace HotChocolate.Types; | ||
|
|
||
| public sealed class OptInFeatureStabilityDirective | ||
| { | ||
| /// <summary> | ||
| /// Creates a new instance of <see cref="OptInFeatureStabilityDirective"/>. | ||
| /// </summary> | ||
| /// <param name="feature"> | ||
| /// The name of the feature for which to set the stability. | ||
| /// </param> | ||
| /// <param name="stability"> | ||
| /// The stability level of the feature. | ||
| /// </param> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// <paramref name="feature"/> is <c>null</c>. | ||
| /// </exception> | ||
| /// <exception cref="ArgumentNullException"> | ||
| /// <paramref name="stability"/> is <c>null</c>. | ||
| /// </exception> | ||
| public OptInFeatureStabilityDirective(string feature, string stability) | ||
| { | ||
| Feature = feature ?? throw new ArgumentNullException(nameof(feature)); | ||
| Stability = stability ?? throw new ArgumentNullException(nameof(stability)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The name of the feature for which to set the stability. | ||
| /// </summary> | ||
| [GraphQLDescription("The name of the feature for which to set the stability.")] | ||
| public string Feature { get; } | ||
|
|
||
| /// <summary> | ||
| /// The stability level of the feature. | ||
| /// </summary> | ||
| [GraphQLDescription("The stability level of the feature.")] | ||
| public string Stability { get; } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/HotChocolate/Core/src/Types/Types/Directives/OptInFeatureStabilityDirectiveExtensions.cs
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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| namespace HotChocolate.Types; | ||
|
|
||
| public static class OptInFeatureStabilityDirectiveExtensions | ||
| { | ||
| public static ISchemaTypeDescriptor OptInFeatureStability( | ||
glen-84 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this ISchemaTypeDescriptor descriptor, | ||
| string feature, | ||
| string stability) | ||
| { | ||
| return descriptor.Directive(new OptInFeatureStabilityDirective(feature, stability)); | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
src/HotChocolate/Core/src/Types/Types/Directives/OptInFeatureStabilityDirectiveType.cs
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using HotChocolate.Properties; | ||
|
|
||
| namespace HotChocolate.Types; | ||
|
|
||
| /// <summary> | ||
| /// Sets the stability level of an opt-in feature. | ||
| /// </summary> | ||
| public sealed class OptInFeatureStabilityDirectiveType | ||
| : DirectiveType<OptInFeatureStabilityDirective> | ||
| { | ||
| protected override void Configure( | ||
| IDirectiveTypeDescriptor<OptInFeatureStabilityDirective> descriptor) | ||
| { | ||
| descriptor | ||
| .Name(WellKnownDirectives.OptInFeatureStability) | ||
| .Description(TypeResources.OptInFeatureStabilityDirectiveType_TypeDescription) | ||
| .Location(DirectiveLocation.Schema) | ||
| .Repeatable(); | ||
|
|
||
| descriptor | ||
| .Argument(t => t.Feature) | ||
| .Name(WellKnownDirectives.OptInFeatureStabilityFeatureArgument) | ||
| .Description(TypeResources.OptInFeatureStabilityDirectiveType_FeatureDescription) | ||
| .Type<NonNullType<StringType>>(); | ||
|
|
||
| descriptor | ||
| .Argument(t => t.Stability) | ||
| .Name(WellKnownDirectives.OptInFeatureStabilityStabilityArgument) | ||
| .Description(TypeResources.OptInFeatureStabilityDirectiveType_StabilityDescription) | ||
| .Type<NonNullType<StringType>>(); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.