-
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
ObservableQuery is not updated by writeQuery when unsubscribed #12268
Comments
Hi @diesieben07! If you adjust the example slightly, you will see that while the Observable will immediately return with the last value it observed while it was active, it will also respond with a more up-to-date value from cache immediately after. const queryRef = client.watchQuery({ query });
let promise, resolve;
promise = new Promise((r) => (resolve = r));
const s = queryRef.subscribe((v) => {
console.log("subscription", v);
s.unsubscribe();
resolve();
});
await promise;
client.writeQuery({
query,
data: {
company: {
__typename: "Info",
ceo: "Me!",
},
},
});
const s2 = queryRef.subscribe((v) => {
console.log("subscription2", v);
});
setTimeout(() => {
s2.unsubscribe();
}, 500); So here the argument can kinda be made into both directions - is it valid not to immediately have a value (if your fetchPolicy were Can you explain a bit what problems you are running into with the current behaviour? |
Thank you for your response!
The problem manifested for me as follows, when using Apollo in Angular (but could be reproduced in any other FE framework using the same techniques):
The following now happens when a logged-in user visits the page and then logs out:
The way I fixed it is to not share the I don't know anything about the React side of Apollo, but to me it seems like this problem has been recognized by the React hooks, because of this call to The problem can also be fixed by calling |
Issue Description
An
ObservableQuery
retains its old (outdated) value if the cache is written to while no subscriptions are active.Link to Reproduction
https://codesandbox.io/p/devbox/xzzldg
Reproduction Steps
client.watchQuery
and subscribe to the Observable.client.writeQuery
to overwrite the query data.@apollo/client
version3.12.15
The text was updated successfully, but these errors were encountered: