-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
"Cache data may be lost when replacing the <whatever> field of a Query object." - custom merge function is never called #6868
Comments
Can you try it with const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
project: {
merge: true,
}
}
}
}
}) It might be important for these objects to have a |
@benjamn I can confirm that |
I got error
|
@benjamn why do we have to use it like so? Im using three components, which all grab something from the Basket:0 they need. Now with merging it gets merged into a big single Basket:0, but why isn't this done automatically? It feels weird to query what you need, but then also think about this typePolicies. Because when not done, latest query wins and other two components go into blank :( |
References: apollographql/apollo-client#6868 https://www.apollographql.com/docs/react/caching/cache-field-behavior/#merging-non-normalized-objects https://www.apollographql.com/docs/react/caching/cache-field-behavior/#the-merge-function https://www.apollographql.com/docs/react/caching/cache-configuration/#generating-unique-identifiers
…nd this change. Basically the cache didn't automatically recognize how to merge the old and incoming changing values for the field
Intended outcome:
The custom merge function I defined would be called.
Actual outcome:
The custom merge is not called, and the warning persists. The complete warning is:
My custom merge is set up as so:
We do have a few other custom merges (but not on the root Query object) that work fine. Maybe that is related to why this isn't being called.
How to reproduce the issue:
I'm not sure how to get it reproduced in something small.
Versions
System:
OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
Binaries:
Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
Yarn: 1.22.4 - ~/.yarn/bin/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm
Browsers:
Chrome: 83.0.4103.116
Firefox: 78.0.2
npmPackages:
@apollo/client: 3.1.3 => 3.1.3
The text was updated successfully, but these errors were encountered: