-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fusion] Added pre-merge validation rule "ProvidesOnNonCompositeField…
…Rule" (#7883)
- Loading branch information
1 parent
f7096e8
commit c23d62b
Showing
8 changed files
with
215 additions
and
103 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
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)); | ||
} | ||
} | ||
} | ||
} |
129 changes: 26 additions & 103 deletions
129
...Chocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.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 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
Oops, something went wrong.