-
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
refetch never updates cache read function values #7994
Comments
@mohit497 One expectation that comes with this extra layer of caching is that the A good way to keep the cache informed about changes in the underlying data is with a reactive variable: import { InMemoryCache, makeVar } from "@apollo/client";
const localStorageVar = makeVar(localStorage.getItem(key));
function setLocalStorage(newValue) {
localStorage.setItem(key, newValue);
localStorageVar(newValue);
}
const cache = new InMemoryCache({
typePolicies: {
YourType: {
fields: {
someField: {
read() {
// Accessing the reactive variable's value in this context creates a
// dependency between the current query and localStorageVar, which
// allows notifying the cache later, if/when the variable changes.
return localStorageVar();
},
},
},
},
},
}); Another way to cause cache.evict({
id: cache.identify({ __typename: "YourType", id }),
fieldName: "someField",
}) If you don't want the field to temporarily disappear from the cache, a more advanced version of the cache.modify({
id: cache.identify({ __typename: "YourType", id }),
fields: {
someField(value, { INVALIDATE }) {
return INVALIDATE;
},
},
}) Any of these approaches should cause |
@mohit497 let us know if #7994 (comment) doesn't clarify things. Thanks! |
When try to access the client side data in query , the refetch query always returns the cached value, for example if you have client read function taking values form localStorage , it will cache the first value and never return the latest
Intended outcome:
Refetch should call the read function again and get latest client state values
Actual outcome:
Right now the refetch values are cached and updated values are not returned
How to reproduce the issue:
Versions
System:
OS: Linux 5.8 Ubuntu 20.04.2 LTS (Focal Fossa)
Binaries:
Node: 10.19.0 - /usr/bin/node
npm: 6.14.4 - /usr/bin/npm
Browsers:
Firefox: 87.0
npmPackages:
@apollo/client: 3.4.0-beta.23 => 3.4.0-beta.23
The text was updated successfully, but these errors were encountered: