apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.

Home Page:https://apollographql.com/client

Repository from Github https://github.comapollographql/apollo-clientRepository from Github https://github.comapollographql/apollo-client

Field is cached separately when args are not set vs set to null

jbachhardie opened this issue · comments

Issue Description

When a query omits arguments from a field that field is cached as fieldName whereas when a query defined those arguments as optional but then they are not passed in as variables it is cached as fieldName({}) despite both of those cases being identical from the point of view of the GraphQL server. This is surprising and causes an issue where a query with the ability to set field arguments can never read from a cache set by a query that does not have those arguments, no matter what variables are set.

Link to Reproduction

https://codesandbox.io/p/devbox/damp-star-6vkn89?workspaceId=ws_NweYYNTBLCG39JiWfDJEb

Reproduction Steps

Click on "Switch" and watch the components switch from a query without args to one with args but where they're not set in the variables. These two queries should share a single cached value but they do not, two different values are stored.

@apollo/client version

3.11.4

Related issues:

Was this useful? Use the reactions below to give feedback.

Thank you for bringing this up - I've opened #12370 to address this. Could you please try out the PR build from that issue and report back if it behaves as expected for you now?