-
-
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 "ProvidesFieldsHasArgumentsR…
…ule" (#7884)
- Loading branch information
Showing
9 changed files
with
332 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
33 changes: 33 additions & 0 deletions
33
...n-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ProvidesFieldsHasArgumentsRule.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,33 @@ | ||
using HotChocolate.Fusion.Events; | ||
using static HotChocolate.Fusion.Logging.LogEntryHelper; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Rules; | ||
|
||
/// <summary> | ||
/// The <c>@provides</c> directive specifies fields that a resolver provides for the parent type. | ||
/// The <c>fields</c> argument must reference fields that do not have arguments, as fields with | ||
/// arguments introduce variability that is incompatible with the consistent behavior expected of | ||
/// <c>@provides</c>. | ||
/// </summary> | ||
/// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec-Provides-Fields-Has-Arguments"> | ||
/// Specification | ||
/// </seealso> | ||
internal sealed class ProvidesFieldsHasArgumentsRule : IEventHandler<ProvidesFieldEvent> | ||
{ | ||
public void Handle(ProvidesFieldEvent @event, CompositionContext context) | ||
{ | ||
var (providedField, providedType, providesDirective, field, type, schema) = @event; | ||
|
||
if (providedField.Arguments.Count != 0) | ||
{ | ||
context.Log.Write( | ||
ProvidesFieldsHasArguments( | ||
providedField.Name, | ||
providedType.Name, | ||
providesDirective, | ||
field.Name, | ||
type.Name, | ||
schema)); | ||
} | ||
} | ||
} |
Oops, something went wrong.