You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: preserve sources for fragment variable values
the new flow for coercing input literals (see graphql#3814 introduces a `replaceVariables()` prior to calling `coerceInputLiteral()` such that we go from `ValueNode` => `ConstValueNode` => coerced value. (With the main advantages being (1) that we can trivially support embedding variables within complex scalars -- despite this being non-spec defined behavior -- and (2) that implementations of custom scalar `coerceInputLiteral()` methods do not need to worry about handling variables or fragment variables.
We previously 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.
To consider:
Within `getFragmentVariableValues()`, because we end up within a `ConstValueNode` stored on source, to coerce this value, we could consider extracting only the functionality we need from `experimentalGetArgumentValues()` (which also handles variables). This would seem to also have the side benefit of removing the need for a separate new signature for this function that can handle fragment spread arguments and we could stick with the old signature/name of just `getArgumentValues()`.
0 commit comments