Skip to content
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

FieldFunctionOptions return incorrect variables #9804

Closed
stardustxx opened this issue Jun 9, 2022 · 1 comment · Fixed by #9808
Closed

FieldFunctionOptions return incorrect variables #9804

stardustxx opened this issue Jun 9, 2022 · 1 comment · Fixed by #9808
Labels
🧞 fixed-by-contributor issues where the contributor went the extra mile and fixed the problem with a PR

Comments

@stardustxx
Copy link
Contributor

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 and readField functions if necessary.

Code may look something like this:

fields: {
  isCanada: {
    read(_, { readField }) {
      return readField("name") === "Canada";
    }
  },
  name: {
    read(name, { variables }) {
      return name;
    }
  }
}

The variables in the read function should always return the actual variable passed to this particular query. So something like:

{
  code: "CA"
}

Actual outcome:

Instead of returning the actual variables, it returns other metadata like:
image

The actual variables are in variables.variables now

How 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 to normalizeReadFieldOptions function and later options.variables would essentially equal to that context object

normalizeReadFieldOptions(arguments, objectOrReference, context),

In 3.4.13, options.variables would equal to the variables object


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

@jpvajda jpvajda added 🔍 investigate Investigate further 🏓 awaiting-team-response requires input from the apollo team labels Jun 10, 2022
@benjamn benjamn removed 🏓 awaiting-team-response requires input from the apollo team 🔍 investigate Investigate further labels Jun 10, 2022
@benjamn benjamn added this to the v3.6.x patch releases milestone Jun 10, 2022
@benjamn benjamn added the 🧞 fixed-by-contributor issues where the contributor went the extra mile and fixed the problem with a PR label Jun 10, 2022
benjamn pushed a commit that referenced this issue Jun 10, 2022
@benjamn
Copy link
Member

benjamn commented Jun 10, 2022

Thanks for reporting this issue (and then fixing it!) @stardustxx!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧞 fixed-by-contributor issues where the contributor went the extra mile and fixed the problem with a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants