-
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.writeQuery in update on OptimisticResponse #4760
Comments
I am having a similar issue, although without using optimistic response at all.
might fix your issue, if it's the same weird one I'm investigating. |
I restructured my components with the mutations being the parent, so the mutations re-render and it's children consequently rerender. I made the Query component the child component. |
On further investigation I have found that it is not safe to modify the return value of The reason my trick with doing a shallow copy of the query worked is that using a different object there affected the cache key apollo was using, so it returned a new object. Using the same document for the query meant that calls to When the In the past there have been some examples and possibly even documentation suggesting that it is safe to mutate the return value of In conclusion: to avoid weird caching problems, do not modify data returned from |
For example the old GitHunt app mutates the result of https://github.com/apollographql/GitHunt-React/blob/master/src/routes/CommentsPage.js#L231 But its replacement in |
Good findings. My memory could be failing me on this, but as far as I remember copy-on-write approach did not work for me. Some documentation around this will surely help be more confident that this is how it works and is supposed to work. |
@dobesv Thanks for that.
|
CONTEXT: PROBLEM: SOLUTION: SOLUTION:
TIPS: I hope this helps someone! ❤ |
Please try a recent version of |
On an optimisticResponse, the cache.writeQuery inside update, triggers the query only for the optimistic data. It doesn't trigger the query ( and hence re-render) when the update function runs the second time with the fetched data.
I would like it to trigger the query every time the cache.writeQuery runs.
Below is how the mutation, optimistic response and update functions look.
The text was updated successfully, but these errors were encountered: