Intended outcome:
Store local state in apollo cache and when updating the local state then all components that have a useQuery against that data will be updated.
Actual outcome:
It appears only the first subscriber to the useQuery receives updates.
How to reproduce the issue:
At the following code sandbox you can see some local state stored in apollo. There are three components that are rendering the result of the same useQuery query. When the Child component calls a mutation on that data, only the Parent component updates. Both the Child component and the OtherChild component do not update.
If the query is removed from the Parent component, then only the Child component updates.
If the query is removed from both the Parent and Child, then the OtherChild component updates.
https://codesandbox.io/s/apollo-client-prob-6ywxk
Versions
It seems related to #5644
I believe @benjamn could help
This bug is currently eating my soul bit by bit.
To escape this nightmare, I'm currently duplicating my queries so they are unique to the component. Is there a better way?
This bug is currently eating my soul bit by bit.
To escape this nightmare, I'm currently duplicating my queries so they are unique to the component. Is there a better way?
I had a "no-duh" moment and centralized my query from my components to the parent. Sanity restored.
@JohnBerlin, you can revert back that conditional - https://github.com/apollographql/apollo-client/pull/5644#discussion_r352922315
But I believe there should be more clear way to support it.
You can just use version: @apollo/client 3.0.0-beta.14
@JohnBerlin, you can revert back that conditional - #5644 (comment)
But I believe there should be more clear way to support it.
You can just use version: @apollo/client 3.0.0-beta.14
Thank you!
Thanks very much to @dusty for opening this issue and providing a simple reproduction, and to @OlegLustenko for tracking down the probable cause!
Please try updating to @apollo/[email protected], which contains PR #5747, when you have a chance.
This bug is currently eating my soul bit by bit.
@JohnBerlin Is that because you were trying to diagnose the bug and fix it, and you found the internals of the cache hard to understand? If so, I can definitely empathize. Not everyone understands this system as well as I do, and it's not your responsibility to find solutions like #5747.
It is your responsibility, however, to remember that you're using beta software, and that we all share the same basic goals. Once you get into that mindset, I think you'll find words like "eating my soul" and "nightmare" no longer feel appropriate.
Take that advice, or leave it. I'll fix the bugs either way.
Most helpful comment
Thanks very much to @dusty for opening this issue and providing a simple reproduction, and to @OlegLustenko for tracking down the probable cause!
Please try updating to
@apollo/[email protected], which contains PR #5747, when you have a chance.@JohnBerlin Is that because you were trying to diagnose the bug and fix it, and you found the internals of the cache hard to understand? If so, I can definitely empathize. Not everyone understands this system as well as I do, and it's not your responsibility to find solutions like #5747.
It is your responsibility, however, to remember that you're using beta software, and that we all share the same basic goals. Once you get into that mindset, I think you'll find words like "eating my soul" and "nightmare" no longer feel appropriate.
Take that advice, or leave it. I'll fix the bugs either way.