Compare composite argument values in sameValue (#108) - #459
Open
jaideeppyne wants to merge 1 commit into
Open
Conversation
sameValue compared only Kind and Raw. Object and list values keep their
contents in Children with an empty Raw, so every object value compared equal to
every other object value (and likewise for lists). OverlappingFieldsCanBeMerged
(spec section 5.3.2) therefore failed to flag same-response-name fields whose
object or list arguments differ, e.g. f(where:{code:"DE"}) and
f(where:{code:"US"}) were allowed to merge.
Compare the children too: input object fields by name (order is not
significant per the spec) and list elements by position (order is
significant). Scalars are unaffected since they carry no children.
Adds a sameValue unit test covering objects, lists, reordering and field-count
mismatches; the object/list cases fail without this change.
Signed-off-by: jaideeppyne <jaideeppyne1997@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Fixes #108.
OverlappingFieldsCanBeMergedfails to flag same-response-name fields whose object or list arguments differ, so genuinely conflicting queries pass validation:{ a: country(where: { code: "DE" }) a: country(where: { code: "US" }) # should conflict, but is allowed to merge }Why
sameValuecompares onlyKindandRaw:But in the AST, object and list values keep their contents in
Childrenand leaveRawempty (seeast/value.go). So everyObjectValuecompares equal to every otherObjectValue, and likewise for lists. Per the GraphQL spec (§5.3.2, Field Selection Merging), fields sharing a response name must have identical arguments — a deep input-value comparison — or be aliased. Ignoring the children silently permits ambiguous queries to merge.How
After the existing
Kind/Rawchecks, compare the children too:ChildValueList.ForName.Scalars are unaffected (they carry no children, so the loop is a no-op and the
Rawcheck still decides).Tests
Added
Test_sameValuetooverlapping_fields_can_be_merged_test.go, covering:go test ./...passes across the module, including the imported graphql-js spec suite (which covers allows different order of input object fields in arg values).Disclosure: this change was prepared with AI assistance and reviewed/verified by me before submission.