-
-
Notifications
You must be signed in to change notification settings - Fork 754
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 remove-unused-methods-from-IError
- Loading branch information
Showing
34 changed files
with
1,368 additions
and
31 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
9 changes: 9 additions & 0 deletions
9
...hocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Info/FieldArgumentInfo.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,9 @@ | ||
using HotChocolate.Skimmed; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Info; | ||
|
||
internal record FieldArgumentInfo( | ||
InputFieldDefinition Argument, | ||
OutputFieldDefinition Field, | ||
INamedTypeDefinition Type, | ||
SchemaDefinition Schema); |
8 changes: 8 additions & 0 deletions
8
...otChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Info/InputFieldInfo.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,8 @@ | ||
using HotChocolate.Skimmed; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Info; | ||
|
||
internal record InputFieldInfo( | ||
InputFieldDefinition Field, | ||
INamedTypeDefinition Type, | ||
SchemaDefinition Schema); |
8 changes: 8 additions & 0 deletions
8
...tChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Info/OutputFieldInfo.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,8 @@ | ||
using HotChocolate.Skimmed; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Info; | ||
|
||
internal record OutputFieldInfo( | ||
OutputFieldDefinition Field, | ||
INamedTypeDefinition Type, | ||
SchemaDefinition Schema); |
5 changes: 5 additions & 0 deletions
5
src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Info/TypeInfo.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,5 @@ | ||
using HotChocolate.Skimmed; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Info; | ||
|
||
internal record TypeInfo(INamedTypeDefinition Type, SchemaDefinition Schema); |
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
61 changes: 61 additions & 0 deletions
61
...on-vnext/src/Fusion.Composition/PreMergeValidation/Rules/InputFieldDefaultMismatchRule.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,61 @@ | ||
using System.Collections.Immutable; | ||
using HotChocolate.Fusion.Events; | ||
using HotChocolate.Language; | ||
using static HotChocolate.Fusion.Logging.LogEntryHelper; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Rules; | ||
|
||
/// <summary> | ||
/// <para> | ||
/// Input fields in different source schemas that have the same name are required to have consistent | ||
/// default values. This ensures that there is no ambiguity or inconsistency when merging input | ||
/// fields from different source schemas. | ||
/// </para> | ||
/// <para> | ||
/// A mismatch in default values for input fields with the same name across different source schemas | ||
/// will result in a schema composition error. | ||
/// </para> | ||
/// </summary> | ||
/// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec-Input-Field-Default-Mismatch"> | ||
/// Specification | ||
/// </seealso> | ||
internal sealed class InputFieldDefaultMismatchRule : IEventHandler<InputFieldGroupEvent> | ||
{ | ||
public void Handle(InputFieldGroupEvent @event, CompositionContext context) | ||
{ | ||
var (_, fieldGroup, typeName) = @event; | ||
|
||
var fieldGroupWithDefaultValues = fieldGroup | ||
.Where(i => i.Field.DefaultValue is not null) | ||
.ToImmutableArray(); | ||
|
||
var defaultValues = fieldGroupWithDefaultValues | ||
.Select(i => i.Field.DefaultValue!) | ||
.ToImmutableHashSet(SyntaxComparer.BySyntax); | ||
|
||
if (defaultValues.Count <= 1) | ||
{ | ||
return; | ||
} | ||
|
||
for (var i = 0; i < fieldGroupWithDefaultValues.Length - 1; i++) | ||
{ | ||
var (fieldA, _, schemaA) = fieldGroupWithDefaultValues[i]; | ||
var (fieldB, _, schemaB) = fieldGroupWithDefaultValues[i + 1]; | ||
var defaultValueA = fieldA.DefaultValue!; | ||
var defaultValueB = fieldB.DefaultValue!; | ||
|
||
if (!SyntaxComparer.BySyntax.Equals(defaultValueA, defaultValueB)) | ||
{ | ||
context.Log.Write( | ||
InputFieldDefaultMismatch( | ||
defaultValueA, | ||
defaultValueB, | ||
fieldA, | ||
typeName, | ||
schemaA, | ||
schemaB)); | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...sion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/LookupMustNotReturnListRule.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,27 @@ | ||
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 avoid ambiguity in entity resolution, such fields must return a | ||
/// single object and not a list. This validation rule enforces that any field annotated with | ||
/// <c>@lookup</c> must have a return type that is <b>NOT</b> a list. | ||
/// </summary> | ||
/// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec--lookup-must-not-return-a-list"> | ||
/// Specification | ||
/// </seealso> | ||
internal sealed class LookupMustNotReturnListRule : IEventHandler<OutputFieldEvent> | ||
{ | ||
public void Handle(OutputFieldEvent @event, CompositionContext context) | ||
{ | ||
var (field, type, schema) = @event; | ||
|
||
if (ValidationHelper.IsLookup(field) && field.Type.NullableType() is ListTypeDefinition) | ||
{ | ||
context.Log.Write(LookupMustNotReturnList(field, type, schema)); | ||
} | ||
} | ||
} |
Oops, something went wrong.