-
-
Notifications
You must be signed in to change notification settings - Fork 787
Ignore ObjectFieldNode ordering when checking if selections can be merged #8432
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
Open
tobias-tengler
wants to merge
7
commits into
main
Choose a base branch
from
tte/fix-input-field-merging-validation-rule
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+303
−3
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd465ae
Add reproduction
tobias-tengler 7548ded
Fix ObjectValueNode comparison
tobias-tengler 9e5a150
No bad kitty. No recursive!
tobias-tengler 00440d2
Handle list value nodes
tobias-tengler 029d029
Improve performance and handle empty object case
tobias-tengler f9df1ac
Move implementation to SyntaxEqualityComparer
tobias-tengler 621e9c1
Order ObjectValueNode fields for HashCode computation
tobias-tengler 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
3 changes: 3 additions & 0 deletions
3
src/HotChocolate/Core/test/Validation.Tests/Models/ComplexInput3.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,3 @@ | ||
namespace HotChocolate.Validation; | ||
|
||
public record ComplexInput3(string Name, string Owner, List<ComplexInput3>? ChildList = null); |
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
29 changes: 29 additions & 0 deletions
29
...n.Tests/__snapshots__/FieldSelectionMergingRuleTests.ConflictingInputFieldListValues.snap
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,29 @@ | ||
[ | ||
{ | ||
"Message": "Encountered fields for the same object that cannot be merged.", | ||
"Code": null, | ||
"Path": null, | ||
"Locations": [ | ||
{ | ||
"Line": 2, | ||
"Column": 5 | ||
}, | ||
{ | ||
"Line": 5, | ||
"Column": 5 | ||
} | ||
], | ||
"Extensions": { | ||
"declaringTypeA": "Query", | ||
"declaringTypeB": "Query", | ||
"fieldA": "findDog3", | ||
"fieldB": "findDog3", | ||
"typeA": "Dog", | ||
"typeB": "Dog", | ||
"responseNameA": "findDog3", | ||
"responseNameB": "findDog3", | ||
"specifiedBy": "https://spec.graphql.org/October2021/#sec-Field-Selection-Merging" | ||
}, | ||
"Exception": null | ||
} | ||
] |
29 changes: 29 additions & 0 deletions
29
...ation.Tests/__snapshots__/FieldSelectionMergingRuleTests.ConflictingInputFieldValues.snap
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,29 @@ | ||
[ | ||
{ | ||
"Message": "Encountered fields for the same object that cannot be merged.", | ||
"Code": null, | ||
"Path": null, | ||
"Locations": [ | ||
{ | ||
"Line": 2, | ||
"Column": 5 | ||
}, | ||
{ | ||
"Line": 9, | ||
"Column": 5 | ||
} | ||
], | ||
"Extensions": { | ||
"declaringTypeA": "Query", | ||
"declaringTypeB": "Query", | ||
"fieldA": "findDog", | ||
"fieldB": "findDog", | ||
"typeA": "Dog", | ||
"typeB": "Dog", | ||
"responseNameA": "findDog", | ||
"responseNameB": "findDog", | ||
"specifiedBy": "https://spec.graphql.org/October2021/#sec-Field-Selection-Merging" | ||
}, | ||
"Exception": null | ||
} | ||
] |
29 changes: 29 additions & 0 deletions
29
...s/__snapshots__/FieldSelectionMergingRuleTests.ConflictingNestedInputFieldListValues.snap
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,29 @@ | ||
[ | ||
{ | ||
"Message": "Encountered fields for the same object that cannot be merged.", | ||
"Code": null, | ||
"Path": null, | ||
"Locations": [ | ||
{ | ||
"Line": 2, | ||
"Column": 5 | ||
}, | ||
{ | ||
"Line": 7, | ||
"Column": 5 | ||
} | ||
], | ||
"Extensions": { | ||
"declaringTypeA": "Query", | ||
"declaringTypeB": "Query", | ||
"fieldA": "findDog3", | ||
"fieldB": "findDog3", | ||
"typeA": "Dog", | ||
"typeB": "Dog", | ||
"responseNameA": "findDog3", | ||
"responseNameB": "findDog3", | ||
"specifiedBy": "https://spec.graphql.org/October2021/#sec-Field-Selection-Merging" | ||
}, | ||
"Exception": null | ||
} | ||
] |
29 changes: 29 additions & 0 deletions
29
...Tests/__snapshots__/FieldSelectionMergingRuleTests.ConflictingNestedInputFieldValues.snap
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,29 @@ | ||
[ | ||
{ | ||
"Message": "Encountered fields for the same object that cannot be merged.", | ||
"Code": null, | ||
"Path": null, | ||
"Locations": [ | ||
{ | ||
"Line": 2, | ||
"Column": 5 | ||
}, | ||
{ | ||
"Line": 9, | ||
"Column": 5 | ||
} | ||
], | ||
"Extensions": { | ||
"declaringTypeA": "Query", | ||
"declaringTypeB": "Query", | ||
"fieldA": "findDog", | ||
"fieldB": "findDog", | ||
"typeA": "Dog", | ||
"typeB": "Dog", | ||
"responseNameA": "findDog", | ||
"responseNameB": "findDog", | ||
"specifiedBy": "https://spec.graphql.org/October2021/#sec-Field-Selection-Merging" | ||
}, | ||
"Exception": null | ||
} | ||
] |
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -357,7 +357,36 @@ private bool Equals(ObjectTypeExtensionNode x, ObjectTypeExtensionNode y) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Equals(x.Fields, y.Fields); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
private bool Equals(ObjectValueNode x, ObjectValueNode y) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
=> Equals(x.Fields, y.Fields); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (x.Fields.Count != y.Fields.Count) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (var i = 0; i < x.Fields.Count; i++) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
var xField = x.Fields[i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
ObjectFieldNode? matchingField = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (var j = 0; j < y.Fields.Count; j++) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
var yField = y.Fields[j]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (Equals(xField.Name, yField.Name)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
matchingField = yField; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (matchingField is null || !Equals(xField.Value, matchingField.Value)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+366
to
+383
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This nested loop results in O(n²) comparisons for each
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
private bool Equals(OperationDefinitionNode x, OperationDefinitionNode y) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
=> SyntaxComparer.BySyntax.Equals(x.Name, y.Name) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1060,9 +1089,8 @@ private int GetHashCode(ObjectValueNode node) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
var hashCode = new HashCode(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
hashCode.Add(node.Kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (var i = 0; i < node.Fields.Count; i++) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
foreach (var field in node.Fields.OrderBy(field => field.Name.Value, StringComparer.Ordinal)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
var field = node.Fields[i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
hashCode.Add(GetHashCode(field)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.