fix(replaceVariables): preserve sources for fragment variable values #4389
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.
The new flow for coercing input literals -- see #3814 -- introduces a
replaceVariables()
prior to callingcoerceInputLiteral()
such that we go:from
ValueNode
=>ConstValueNode
=> coerced valueThe main advantages being that:
(1) we can trivially support embedding variables within complex scalars -- despite this being non-spec defined behavior!
(2) userland implementations of custom scalar
coerceInputLiteral()
methods do not need to worry about handling variables or fragment variables.Prior to this PR, we did not properly handle this in the case of fragment definition variables/fragment spread arguments.
replaceVariableValues()
assumes that the uncoerced value is preserved as source, but instead of grabbing this value from the argument on the spread, we were incorrectly attempting to retrieve the already stored value from existing variables.This was not caught because we previously did not have any actual tests for this custom unspecified behavior and were using incorrect types and bespoke builders in our tests for
replaceVariables()
.This PR:
(a) fixes the bug by storing the argument from the spread
(b) fixes our bespoke builders in
replaceVariables()
(c) add explicit tests for embedding variables within custom scalars to protect against future changes.
As a post-script, because within
getFragmentVariableValues()
we now end up within aValueNode
stored on source, to coerce this value, we can extract a new helpercoerceArgumentValue()
fromexperimentalGetArgumentValues()
, rather than calling it after we are done for all the values, which has some additional overhead.This has the side benefit of removing the need for a separate
experimentalGetArgumentValues()
function altogether. We initially introduced it to have a more flexible signature forgetArgumentValues()
that encompasses argument for fragment spreads, but now this is taken care of using our more directed helper.