Replies: 2 comments 1 reply
-
The simplest approach is to update the queries that you see on the screen and Invalide the rest with invalidateQueries. Those other queries will then refetch when they are used the next time. Other solution would be to sync manually with setQueryData but that’s pretty tedious and error prone. |
Beta Was this translation helpful? Give feedback.
-
It would be amazing if there was a cache read/write library that we could opt into that does something like https://formidable.com/open-source/urql/docs/graphcache/cache-updates/ if for instance we could get either the server to automatically send id+typename or augment client side then we could have a caching library that follows the convention and so optimistic updates while waiting on the cache to refresh. The default to updates would be merge but we could also have a delete action to remove from an item or collection followed by a simpler cache update override option. I guess the problem is representing this as a dependency graph to know where to update things. Still this would solve a huge class of problems for keeping the cache optimistically in synch as soon as possible rather than wait for a round trip or even an onSuccess. Is this too crazy to work? Urql and Apollo have a different data structure and the problem is definitely challenging but maybe possible to solve? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a simple CRUD API, where I can fetch entities by:
After digging on the docs and GH discussions I figured that having those two functionalities access the same cache location isn't supported natively by the library and I need to implement such caching logic using the
QueryClient
methods.My initial thought was to have this cache structure:
Where both queries would use and populate it according to any CRUD operation (I took some inspiration for
apollo-client
normalized cache structure)After some time I came to realize that it'd be quite hard for me to sync between the
contextId
map and eachentityId
(for e.g - when I remove an entity by id, I'm not aware of the context id that it might have been fetched by, hence I can't remove it from that map and so it leaves the cache out of sync).I was wondering what's the best approach for me to keep the cache in sync? Perhaps having some cache references or subscriptions. I'd also be glad to hear any thoughts of such normalized cache and whether or not it's a misuse of this library.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions