FieldFunctionOptions return incorrect variables #9804
Labels
🧞 fixed-by-contributor
issues where the contributor went the extra mile and fixed the problem with a PR
Milestone
Intended outcome:
Prior to 3.5.0 and according to the doc, we can add a local-only field and utilize the policy file to populate the data by using the
read
andreadField
functions if necessary.Code may look something like this:
The
variables
in theread
function should always return the actual variable passed to this particular query. So something like:Actual outcome:
Instead of returning the actual variables, it returns other metadata like:

The actual variables are in
variables.variables
nowHow to reproduce the issue:
Set up a local field and the read function for that field. In that read function, have it access another field using
readField
function. Set up another read function for the field being accessed, then console log the variables.https://codesandbox.io/s/quizzical-panka-x9v60j?file=/src/index.js
Sorry I know I'm probably not supposed to share speculation but this is what I've found:
In 3.5.0, it passes the
context
object tonormalizeReadFieldOptions
function and lateroptions.variables
would essentially equal to thatcontext
objectapollo-client/src/cache/inmemory/policies.ts
Line 915 in 538b795
In 3.4.13,
options.variables
would equal to thevariables
objectapollo-client/src/cache/inmemory/policies.ts
Line 884 in 9214160
There was probably a reason I wasn't aware of but just want to share what I've found, thank you
Versions
System:
OS: macOS 12.3.1
Binaries:
Node: 14.19.3 - /usr/local/opt/node@14/bin/node
npm: 6.14.17 - /usr/local/opt/node@14/bin/npm
Browsers:
Chrome: 102.0.5005.61
Edge: 102.0.1245.33
Firefox: 101.0
Safari: 15.4
npmPackages:
@apollo/client: ^3.5.0 => 3.5.0
The text was updated successfully, but these errors were encountered: