-
Notifications
You must be signed in to change notification settings - Fork 117
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-persist not persisting optimisticResponse data #410
Comments
Cache consisting of multiple layers - with optimistic layers that made up projection but are not actually applied. When designed optimistic operations were made typically short lived as they lifespan is usually couple seconds. Persisting those is going to introduce number of challenges:
See also aerogear/offix#118 Saving optimistic data would require changes in Apollo Client itself (to restore them) later so this is more like feature request |
Hi Wojtek, Thanks for that info. It sounds like you're saying there would be difficulty in persisting the data in each layer of the cache, and then restoring the data back to the specific layers that they came from. Would it be correct to say though, that if I could figure out how to move the data from the short-lived optimistic response layer to the longer-lived cache layer, that cache-persist would then automatically persist and restore that data? I don't need optimistic data to be restored as optimistic data, I'd rather just figure out how to have optimistic data automatically move into the longer-lived layer. I've tried doing this using useMutation's
showing me the data that I'd just inserted via Can you give me any hints as far as
|
If we apply changes to cache that is not representing state of server, we are hitting cache invalidation issue (from famous "there are two things hard in software.." I have feeling that you are looking probably for something like WORA library done by @morrys. |
Thanks for the feedback. I've been trying to do offline-first with @apollo/client + persistCache, retryLink, queueLink. Based on your comments, I'll see if I get further with offix, and I'll check out wora as well. |
WORA would be more suitable for the case explained. |
I've attempted to achieve offline-first support based on Apollo (& link family) about a year ago. I'd like to warn you about that approach though - as the app is getting bigger, maintaining everything in sync is a mess and requires a lot of boilerplate. |
Thanks @wodCZ, I was looking at that article as well. I don't really understand what the pros and cons are in functionality in wora vs offix (@wtrocki can you comment on this?) but my thoughts on the three you mention:
As per wtrocki, offix may not be the right tool for me, but instinct says to at least try it out and see if I get further than with apollo + link family Edit: I realized Wora has in fact been updated recently, just not in master. |
I've ended up with some kind of Model - View - Controller architecture. As I'm writing this I realise how this sounds like overkill. I've came to conclusion that apps with read-only support are just fine with simple react + apollo + cache-persist approach, but at the moment you need read-and-write offline functionality, any attempts to abuse apollo cache for such support is not worth the hassle. I was a bit relieved when I saw wtrocki confirm my thoughts saying this:
Having the model separated from the view seems like clear way to work with fully offline apps. At least, I feel more confident about the app ever since I've rewritten the app 3 months ago. In any case, I can't call myself an expert 😁 also, at the time, I didn't find Offix nor Wora - maybe they'd satisfy my needs. |
I’m going to close this issue given the wealth of detail provided in the comments. I’d also like to add for such use-cases something like |
I'm doing some exploring with apollo-cache-persist and apollo-link-queue. My mutations set an optimisticResponse, which, aside from apollo-cache-persist not persisting data when queueLink is closed, does seem to do what I expect:
cache
tab of Apollo Client DevtoolsI think that (but not 100% on) setting an optimisticResponse doesn't necessarily directly affect the cache even though it updates variables created with useQuery
But
cache
tab of Apollo Client Devtools is actually in the cache, and not in this possible other place mentioned in the previous point.With the cache-persist
debug
option set totrue
, I do see a message about persisted data arrive in the appropriate moment, but it mentions storing only 2 characters of data ({}
).Again, the above is what I observe when queueLink is closed. When queueLink is open, cache-persist does work the way I expect (because it's coming from the server response), and gives a message about storing a larger, more appropriate number of characters.
Based on what I'm observing, it seems like either:
or
cache
tab of Apollo Client Devtools actually shows more than justcache
.Neither of which would be expected.
What am I doing wrong here? How can I persist data that winds up in the cache only in virtue of optimisticResponse, rather than coming from a server response?
Thanks so much!
Justin
The text was updated successfully, but these errors were encountered: