-
-
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.
- Loading branch information
1 parent
4c6d65b
commit f18e747
Showing
7 changed files
with
293 additions
and
281 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
56 changes: 56 additions & 0 deletions
56
...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,56 @@ | ||
using System.Collections.Immutable; | ||
using HotChocolate.Fusion.Events; | ||
using HotChocolate.Skimmed; | ||
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; | ||
|
||
IReadOnlyCollection<OutputFieldInfo> externalFields = | ||
[..fieldGroup.Where(i => ValidationHelper.IsExternal(i.Field))]; | ||
if (externalFields.Count == 0) | ||
{ | ||
return; | ||
} | ||
|
||
var argumentNames = fieldGroup | ||
.SelectMany(i => i.Field.Arguments, (_, arg) => arg.Name) | ||
.ToHashSet(); | ||
|
||
foreach (var argumentName in argumentNames) | ||
{ | ||
IReadOnlyList<InputFieldDefinition> arguments = [..fieldGroup.Select(i => i.Field.Arguments[argumentName])]; | ||
var defaultValue = arguments[0].DefaultValue; | ||
|
||
foreach (var argument in arguments) | ||
{ | ||
var currentDefaultValue = argument.DefaultValue; | ||
var match = (currentDefaultValue, defaultValue) switch | ||
{ | ||
(null, null) => true, | ||
(not null, null) => false, | ||
(null, not null) => false, | ||
_ => currentDefaultValue.Value!.Equals(defaultValue.Value) | ||
}; | ||
|
||
if (!match) | ||
{ | ||
context.Log.Write(ExternalArgumentDefaultMismatch(fieldName, typeName, argumentName)); | ||
} | ||
} | ||
} | ||
} | ||
} |
59 changes: 0 additions & 59 deletions
59
...t/src/Fusion.Composition/PreMergeValidation/Rules/ExternalArgumentsDefaultMismatchRule.cs
This file was deleted.
Oops, something went wrong.
110 changes: 39 additions & 71 deletions
110
...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
Oops, something went wrong.