-
-
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 "KeyFieldsSelectInvalidTypeR…
…ule" (#7871)
- Loading branch information
Showing
11 changed files
with
395 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,7 @@ Storeless | |
strawberryshake | ||
streamable | ||
Structs | ||
subgraphs | ||
sublicensable | ||
supergraph | ||
Swashbuckle | ||
|
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
36 changes: 36 additions & 0 deletions
36
...n-vnext/src/Fusion.Composition/PreMergeValidation/Rules/KeyFieldsSelectInvalidTypeRule.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,36 @@ | ||
using HotChocolate.Fusion.Events; | ||
using HotChocolate.Skimmed; | ||
using static HotChocolate.Fusion.Logging.LogEntryHelper; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation.Rules; | ||
|
||
/// <summary> | ||
/// The <c>@key</c> directive is used to define the set of fields that uniquely identify an entity. | ||
/// These fields must reference scalars or object types to ensure a valid and consistent | ||
/// representation of the entity across subgraphs. Fields of types <c>List</c>, <c>Interface</c>, or | ||
/// <c>Union</c> cannot be part of a <c>@key</c> because they do not have a well-defined unique | ||
/// value. | ||
/// </summary> | ||
/// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec-Key-Fields-Select-Invalid-Type"> | ||
/// Specification | ||
/// </seealso> | ||
internal sealed class KeyFieldsSelectInvalidTypeRule : IEventHandler<KeyFieldEvent> | ||
{ | ||
public void Handle(KeyFieldEvent @event, CompositionContext context) | ||
{ | ||
var (entityType, keyDirective, field, type, schema) = @event; | ||
|
||
var fieldType = field.Type.NullableType(); | ||
|
||
if (fieldType is InterfaceTypeDefinition or ListTypeDefinition or UnionTypeDefinition) | ||
{ | ||
context.Log.Write( | ||
KeyFieldsSelectInvalidType( | ||
entityType.Name, | ||
keyDirective, | ||
field.Name, | ||
type.Name, | ||
schema)); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...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.