-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dr/lookup-non-list
- Loading branch information
Showing
17 changed files
with
937 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
28 changes: 28 additions & 0 deletions
28
...src/Fusion.Composition/PreMergeValidation/Rules/LookupShouldHaveNullableReturnTypeRule.cs
This file contains 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,28 @@ | ||
using HotChocolate.Fusion.Events; | ||
using HotChocolate.Skimmed; | ||
using static HotChocolate.Fusion.Logging.LogEntryHelper; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Rules; | ||
|
||
/// <summary> | ||
/// Fields annotated with the <c>@lookup</c> directive are intended to retrieve a single entity | ||
/// based on provided arguments. To properly handle cases where the requested entity does not exist, | ||
/// such fields should have a nullable return type. This allows the field to return null when an | ||
/// entity matching the provided criteria is not found, following the standard GraphQL practices for | ||
/// representing missing data. | ||
/// </summary> | ||
/// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec--lookup-Should-Have-Nullable-Return-Type"> | ||
/// Specification | ||
/// </seealso> | ||
internal sealed class LookupShouldHaveNullableReturnTypeRule : IEventHandler<OutputFieldEvent> | ||
{ | ||
public void Handle(OutputFieldEvent @event, CompositionContext context) | ||
{ | ||
var (field, type, schema) = @event; | ||
|
||
if (ValidationHelper.IsLookup(field) && field.Type is NonNullTypeDefinition) | ||
{ | ||
context.Log.Write(LookupShouldHaveNullableReturnType(field, type, schema)); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ProvidesOnNonCompositeFieldRule.cs
This file contains 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,34 @@ | ||
using HotChocolate.Fusion.Events; | ||
using HotChocolate.Fusion.Extensions; | ||
using HotChocolate.Skimmed; | ||
using static HotChocolate.Fusion.Logging.LogEntryHelper; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Rules; | ||
|
||
/// <summary> | ||
/// The <c>@provides</c> directive allows a field to “provide” additional nested fields on the | ||
/// composite type it returns. If a field’s base type is not an object or interface type (e.g., | ||
/// String, Int, Boolean, Enum, Union, or an Input type), it cannot hold nested fields for | ||
/// <c>@provides</c> to select. Consequently, attaching <c>@provides</c> to such a field is | ||
/// invalid and raises a PROVIDES_ON_NON_OBJECT_FIELD error. | ||
/// </summary> | ||
/// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec-Provides-on-Non-Composite-Field"> | ||
/// Specification | ||
/// </seealso> | ||
internal sealed class ProvidesOnNonCompositeFieldRule : IEventHandler<OutputFieldEvent> | ||
{ | ||
public void Handle(OutputFieldEvent @event, CompositionContext context) | ||
{ | ||
var (field, type, schema) = @event; | ||
|
||
if (ValidationHelper.HasProvidesDirective(field)) | ||
{ | ||
var fieldType = field.Type.NamedType(); | ||
|
||
if (fieldType is not ComplexTypeDefinition) | ||
{ | ||
context.Log.Write(ProvidesOnNonCompositeField(field, type, schema)); | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...t/src/Fusion.Composition/PreMergeValidation/Rules/RequireDirectiveInFieldsArgumentRule.cs
This file contains 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,34 @@ | ||
using HotChocolate.Fusion.Events; | ||
using static HotChocolate.Fusion.Logging.LogEntryHelper; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Rules; | ||
|
||
/// <summary> | ||
/// The <c>@require</c> directive is used to specify fields on the same type that an argument | ||
/// depends on in order to resolve the annotated field. When using <c>@require(fields: "…")</c>, the | ||
/// <c>fields</c> argument must be a valid selection set string <b>without</b> any additional | ||
/// directive applications. Applying a directive (e.g., <c>@lowercase</c>) inside this selection set | ||
/// is not supported and triggers the <c>REQUIRE_DIRECTIVE_IN_FIELDS_ARG</c> error. | ||
/// </summary> | ||
/// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec-Require-Directive-in-Fields-Argument"> | ||
/// Specification | ||
/// </seealso> | ||
internal sealed class RequireDirectiveInFieldsArgumentRule : IEventHandler<RequireFieldNodeEvent> | ||
{ | ||
public void Handle(RequireFieldNodeEvent @event, CompositionContext context) | ||
{ | ||
var (fieldNode, fieldNamePath, requireDirective, argument, field, type, schema) = @event; | ||
|
||
if (fieldNode.Directives.Count != 0) | ||
{ | ||
context.Log.Write( | ||
RequireDirectiveInFieldsArgument( | ||
fieldNamePath, | ||
requireDirective, | ||
argument.Name, | ||
field.Name, | ||
type.Name, | ||
schema)); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RequireInvalidFieldsTypeRule.cs
This file contains 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,40 @@ | ||
using HotChocolate.Fusion.Events; | ||
using HotChocolate.Language; | ||
using static HotChocolate.Fusion.Logging.LogEntryHelper; | ||
using static HotChocolate.Fusion.WellKnownArgumentNames; | ||
using static HotChocolate.Fusion.WellKnownDirectiveNames; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Rules; | ||
|
||
/// <summary> | ||
/// When using the <c>@require</c> directive, the <c>fields</c> argument must always be a string | ||
/// that defines a (potentially nested) selection set of fields from the same type. If the | ||
/// <c>fields</c> argument is provided as a type other than a string (such as an integer, boolean, | ||
/// or enum), the directive usage is invalid and will cause schema composition to fail. | ||
/// </summary> | ||
/// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec-Require-Invalid-Fields-Type"> | ||
/// Specification | ||
/// </seealso> | ||
internal sealed class RequireInvalidFieldsTypeRule : IEventHandler<FieldArgumentEvent> | ||
{ | ||
public void Handle(FieldArgumentEvent @event, CompositionContext context) | ||
{ | ||
var (argument, field, type, schema) = @event; | ||
|
||
var requireDirective = argument.Directives.FirstOrDefault(Require); | ||
|
||
if ( | ||
requireDirective is not null | ||
&& requireDirective.Arguments.TryGetValue(Fields, out var fields) | ||
&& fields is not StringValueNode) | ||
{ | ||
context.Log.Write( | ||
RequireInvalidFieldsType( | ||
requireDirective, | ||
argument.Name, | ||
field.Name, | ||
type.Name, | ||
schema)); | ||
} | ||
} | ||
} |
Oops, something went wrong.