Question regarding <Optimistic Updates> If the res...
# apollo-kotlin
s
Question regarding Optimistic Updates If the response from the mutation is a failure, due to no internet for example, but we've already written what we'd expect to get back into the cache using optimistUpdates, how should one fix the cache from that point? The UI would at that point show what we'd like the state to be like, but we will after the fact know that the mutation did not go through.
m
Not sure I get the question. The optimistic updates write caches are not persistent. Once the network fails, they will be rolled back
So your UI will rollback too
(which is a pattern I don't really like, I should blog about it)
s
Oh, alright I did not know that. Does it keep a snapshot of what the cache looked like before? How does it know how to roll it back?
m
Indeed, the optimistic updates are kept in a separate, journaled, in-memory only cache
s
Smart! Okay that should be good enough for me to experiment with it then. I just have never played with this before so I got curious 😄
m
I discourage the pattern these days
s
👀
m
If it were only me, I would probably deprecate the feature altogether but we have it on the web + ios and some usage in the field too
It's lying to your users. They think something went through while it did not actually
If they close their app, they may lose some data
If the failure is "fast enough" it's not too much of a problem but if you're on a slow/spotty network, it is definitely an issue
Happened to me with YouTrack in the train the other day
I thought I had an issue starred but in fact, I had not
s
Hmm yeah okay I will admit I agree with you here. I don't know if me reaching for it here was the right thing to do, I wanted mostly to see how it works at first in order to be able to judge that a bit better. But I agree that such an experience is horrible, especially if the action you're doing is important enough.
m
Yea, exactly. I like how GitHub is doing it in their settings, the checkboxes have a small loading indicator next to them to indicate the loading state
👍 1