-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(replaceVariables): preserve sources for fragment variable values #4389
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
Conversation
e6fa60a
to
3f6e32b
Compare
non-specified behavior but supported through v17 (with operation variables)
44d33e4
to
32541f6
Compare
I broke this up into separate commits to aid review. First commit: introduces the failing test. |
by introducing internal helper coerceArgument goals: (1) removes need to build temporary array of `varSignatures` in `getFragmentVariableValues()` (2) removes need to rebuild map of `varSignatures` when `getFragmentVariableValues()` would call `experimentalGetArgumentValues()`. (3) reuses `argumentNode` variable instead of duplicating selection from the `argNodeMap` (4) allows us to preserve original `getArgumentValues()` signature and dispense with `experimentalGetArgumentValues()` altogether.
for now we will disable support for fragment arguments, pending graphql/graphql-js#4389
* minimize TransformationContext * consolidate loops * switch from filtering to actual routing of root fields * for now we will disable support for fragment arguments, pending graphql/graphql-js#4389 * add changeset * fix support for fragment argument * lint
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.