-
-
Notifications
You must be signed in to change notification settings - Fork 785
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
12
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 all commits
Commits
Show all changes
12 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 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
35 changes: 35 additions & 0 deletions
35
.../Core/src/Execution/DependencyInjection/RequestExecutorBuilderExtensions.OptInFeatures.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,35 @@ | ||
using HotChocolate; | ||
using HotChocolate.Execution.Configuration; | ||
using HotChocolate.Types; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
public static partial class RequestExecutorBuilderExtensions | ||
{ | ||
public static IRequestExecutorBuilder OptInFeatureStability( | ||
this IRequestExecutorBuilder builder, | ||
string feature, | ||
string stability) | ||
{ | ||
if (builder is null) | ||
{ | ||
throw new ArgumentNullException(nameof(builder)); | ||
} | ||
|
||
if (feature is null) | ||
{ | ||
throw new ArgumentNullException(nameof(feature)); | ||
} | ||
|
||
if (stability is null) | ||
{ | ||
throw new ArgumentNullException(nameof(stability)); | ||
} | ||
|
||
return Configure( | ||
builder, | ||
options => options.OnConfigureSchemaServicesHooks.Add( | ||
(ctx, _) => ctx.SchemaBuilder.AddSchemaConfiguration( | ||
d => d.Directive(new OptInFeatureStabilityDirective(feature, stability))))); | ||
} | ||
} |
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, | ||
ISchemaDefinition schema, | ||
ICollection<ISchemaError> errors) | ||
{ | ||
if (!context.Options.EnableOptInFeatures) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var type in schema.Types) | ||
{ | ||
switch (type) | ||
{ | ||
case IInputObjectTypeDefinition inputObjectType: | ||
foreach (var field in inputObjectType.Fields) | ||
{ | ||
if (field.Type.IsNonNullType() && field.DefaultValue is null) | ||
{ | ||
var requiresOptInDirectives = field.Directives | ||
.Where(d => d.Definition is RequiresOptInDirectiveType); | ||
|
||
foreach (var _ in requiresOptInDirectives) | ||
{ | ||
errors.Add(RequiresOptInOnRequiredInputField( | ||
inputObjectType, | ||
field)); | ||
} | ||
} | ||
} | ||
|
||
break; | ||
|
||
case IObjectTypeDefinition 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.Definition 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
108 changes: 108 additions & 0 deletions
108
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
54 changes: 54 additions & 0 deletions
54
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,54 @@ | ||
using HotChocolate.Properties; | ||
using HotChocolate.Utilities; | ||
|
||
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="ArgumentException"> | ||
/// <paramref name="feature"/> is not a valid name. | ||
/// </exception> | ||
/// <exception cref="ArgumentException"> | ||
/// <paramref name="stability"/> is not a valid name. | ||
/// </exception> | ||
public OptInFeatureStabilityDirective(string feature, string stability) | ||
{ | ||
if (!feature.IsValidGraphQLName()) | ||
{ | ||
throw new ArgumentException( | ||
TypeResources.OptInFeatureStabilityDirective_FeatureName_NotValid, | ||
nameof(feature)); | ||
} | ||
|
||
if (!stability.IsValidGraphQLName()) | ||
{ | ||
throw new ArgumentException( | ||
TypeResources.OptInFeatureStabilityDirective_Stability_NotValid, | ||
nameof(stability)); | ||
} | ||
|
||
Feature = feature; | ||
Stability = 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)); | ||
} | ||
} |
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.