-
-
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.
[Fusion] Added pre-merge validation rule `ExternalArgumentDefaultMism…
…atch` (#7844)
- Loading branch information
1 parent
f4233d2
commit d1e6ac3
Showing
7 changed files
with
278 additions
and
56 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
53 changes: 53 additions & 0 deletions
53
...xt/src/Fusion.Composition/PreMergeValidation/Rules/ExternalArgumentDefaultMismatchRule.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,53 @@ | ||
using System.Collections.Immutable; | ||
using HotChocolate.Fusion.Events; | ||
using HotChocolate.Language; | ||
using static HotChocolate.Fusion.Logging.LogEntryHelper; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Rules; | ||
|
||
/// <summary> | ||
/// This rule ensures that arguments on fields marked as <c>@external</c> have default values | ||
/// compatible with the corresponding arguments on fields from other source schemas where the field | ||
/// is defined (non-<c>@external</c>). | ||
/// </summary> | ||
/// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec-External-Argument-Default-Mismatch"> | ||
/// Specification | ||
/// </seealso> | ||
internal sealed class ExternalArgumentDefaultMismatchRule : IEventHandler<OutputFieldGroupEvent> | ||
{ | ||
public void Handle(OutputFieldGroupEvent @event, CompositionContext context) | ||
{ | ||
var (fieldName, fieldGroup, typeName) = @event; | ||
|
||
var externalFields = fieldGroup | ||
.Where(i => ValidationHelper.IsExternal(i.Field)) | ||
.ToImmutableArray(); | ||
|
||
if (externalFields.Length == 0) | ||
{ | ||
return; | ||
} | ||
|
||
var argumentNames = fieldGroup | ||
.SelectMany(i => i.Field.Arguments, (_, arg) => arg.Name) | ||
.ToImmutableHashSet(); | ||
|
||
foreach (var argumentName in argumentNames) | ||
{ | ||
var arguments = fieldGroup | ||
.SelectMany(i => i.Field.Arguments.Where(a => a.Name == argumentName)) | ||
.ToImmutableArray(); | ||
|
||
var defaultValue = arguments[0].DefaultValue; | ||
|
||
foreach (var argument in arguments) | ||
{ | ||
if (!SyntaxComparer.BySyntax.Equals(argument.DefaultValue, defaultValue)) | ||
{ | ||
context.Log.Write( | ||
ExternalArgumentDefaultMismatch(argumentName, fieldName, typeName)); | ||
} | ||
} | ||
} | ||
} | ||
} |
80 changes: 24 additions & 56 deletions
80
...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
Oops, something went wrong.