-
-
Notifications
You must be signed in to change notification settings - Fork 803
[Fusion] Add pre-merge validation rule "SpecifiedByUrlMismatchRule" #9306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
6 changes: 6 additions & 0 deletions
6
src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Info/ScalarTypeInfo.cs
This file contains hidden or 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,6 @@ | ||
| using HotChocolate.Types; | ||
| using HotChocolate.Types.Mutable; | ||
|
|
||
| namespace HotChocolate.Fusion.Info; | ||
|
|
||
| internal record ScalarTypeInfo(IScalarTypeDefinition Scalar, MutableSchemaDefinition Schema); |
This file contains hidden or 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 hidden or 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
44 changes: 44 additions & 0 deletions
44
...Fusion-vnext/src/Fusion.Composition/PreMergeValidationRules/SpecifiedByUrlMismatchRule.cs
This file contains hidden or 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,44 @@ | ||
| using HotChocolate.Fusion.Events; | ||
| using HotChocolate.Fusion.Events.Contracts; | ||
| using static HotChocolate.Fusion.Logging.LogEntryHelper; | ||
|
|
||
| namespace HotChocolate.Fusion.PreMergeValidationRules; | ||
|
|
||
| /// <summary> | ||
| /// <para> | ||
| /// This validation rule checks for mismatches in the specified-by URLs of scalar types across | ||
| /// different schemas. If a scalar type is defined in multiple schemas with different specified-by | ||
| /// URLs, a warning is logged to indicate the inconsistency. This helps ensure that clients | ||
| /// consuming the merged schema have a consistent understanding of the scalar type's behavior and | ||
| /// specifications, even if the underlying implementations differ across schemas. | ||
| /// </para> | ||
| /// </summary> | ||
| /// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec-SpecifiedBy-URL-Mismatch"> | ||
| /// Specification | ||
| /// </seealso> | ||
| internal sealed class SpecifiedByUrlMismatchRule : IEventHandler<ScalarTypeGroupEvent> | ||
| { | ||
| public void Handle(ScalarTypeGroupEvent @event, CompositionContext context) | ||
| { | ||
| var (_, typeGroup) = @event; | ||
|
|
||
| for (var i = 0; i < typeGroup.Length - 1; i++) | ||
| { | ||
| var typeInfoA = typeGroup[i]; | ||
| var typeInfoB = typeGroup[i + 1]; | ||
| var specifiedByA = typeInfoA.Scalar.SpecifiedBy; | ||
| var specifiedByB = typeInfoB.Scalar.SpecifiedBy; | ||
|
|
||
| if (specifiedByA != specifiedByB) | ||
| { | ||
| context.Log.Write( | ||
| SpecifiedByUrlMismatch( | ||
| typeInfoA.Scalar, | ||
| typeInfoA.Schema, | ||
| specifiedByA?.ToString(), | ||
| typeInfoB.Schema, | ||
| specifiedByB?.ToString())); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
...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 hidden or 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 hidden or 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
69 changes: 69 additions & 0 deletions
69
.../test/Fusion.Composition.Tests/PreMergeValidationRules/SpecifiedByUrlMismatchRuleTests.cs
This file contains hidden or 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,69 @@ | ||
| namespace HotChocolate.Fusion.PreMergeValidationRules; | ||
|
|
||
| public sealed class SpecifiedByUrlMismatchRuleTests : RuleTestBase | ||
| { | ||
| protected override object Rule { get; } = new SpecifiedByUrlMismatchRule(); | ||
|
|
||
| // All schemas have the same specified-by URL for the "Date" scalar type. | ||
| [Fact] | ||
| public void Validate_SpecifiedByUrlMatch_Succeeds() | ||
| { | ||
| AssertValid( | ||
| [ | ||
| """ | ||
| # Schema A | ||
| scalar Date @specifiedBy(url: "https://example.com/date-spec") | ||
| """, | ||
| """ | ||
| # Schema B | ||
| scalar Date @specifiedBy(url: "https://example.com/date-spec") | ||
| """ | ||
| ]); | ||
| } | ||
|
|
||
| // The schemas have different specified-by URLs for the "Date" scalar type, which should trigger | ||
| // warnings. | ||
| [Fact] | ||
| public void Validate_SpecifiedByUrlMismatch_Fails() | ||
| { | ||
| AssertInvalid( | ||
| [ | ||
| """ | ||
| # Schema A | ||
| scalar Date @specifiedBy(url: "https://example.com/date-spec-1") | ||
| """, | ||
| """ | ||
| # Schema B | ||
| scalar Date @specifiedBy(url: "https://example.com/date-spec-2") | ||
| """, | ||
| """ | ||
| # Schema C | ||
| scalar Date | ||
| """ | ||
| ], | ||
| [ | ||
| """ | ||
| { | ||
| "message": "The scalar type 'Date' has a different specified-by URL in schema 'A' (https://example.com/date-spec-1) than it does in schema 'B' (https://example.com/date-spec-2).", | ||
| "code": "SPECIFIED_BY_URL_MISMATCH", | ||
| "severity": "Warning", | ||
| "coordinate": "Date", | ||
| "member": "Date", | ||
| "schema": "A", | ||
| "extensions": {} | ||
| } | ||
| """, | ||
| """ | ||
| { | ||
| "message": "The scalar type 'Date' has a different specified-by URL in schema 'B' (https://example.com/date-spec-2) than it does in schema 'C' (null).", | ||
| "code": "SPECIFIED_BY_URL_MISMATCH", | ||
| "severity": "Warning", | ||
| "coordinate": "Date", | ||
| "member": "Date", | ||
| "schema": "B", | ||
| "extensions": {} | ||
| } | ||
| """ | ||
| ]); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.