Fix merged source name generation when shared root is operation root #3073
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.
This fixes #3071
When the shared root of a merged source is the direct parent or a direct sibling, we remove the parent from the namespacing of the referenced selection set. If the shared root is the root of the operation/fragment, that component of the namespacing should be removed.
Since the change to the way we indicate the location of a
SelectionSet
in theIR
changed in #3045, in this case, the shared root is now not part of thefieldPath
, causing the "shared root" to be at an index of-1
(because its represented by thelocation.source
now). This was causing a crash with an invalid range bounds.This PR fixes this by using
max(0, sharedRootIndex)
to ensure we don't use-1
, and then not removing the first component in that case (because that component would be thelocation.source
which is already not included.