Skip to content
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

Restoring optimistic response after application restarts? #3

Open
wtrocki opened this issue Jul 17, 2019 · 11 comments
Open

Restoring optimistic response after application restarts? #3

wtrocki opened this issue Jul 17, 2019 · 11 comments
Labels
apollo-offline question Further information is requested

Comments

@wtrocki
Copy link

wtrocki commented Jul 17, 2019

@wora/offline-first support restoring optimitisic responses into cache?
Do you see persisting optimistic response layer in the future or library will apply this some different way?

@morrys
Copy link
Owner

morrys commented Jul 17, 2019

@wora/offline-first is not in charge of managing the status of the application that uses it, but makes it easier to manage requests that are sent to the server when you are not online.

This through a utility function to know the connection status addNetInfoListener and a function to insert the request in the queue of offline publish requests.

Finally, when the status returns online, the queue execution workflow is executed and the library allows simple options to extend the default behavior of the extension.
https://github.com/morrys/wora/tree/master/packages/offline-first#options

This workflow will soon be well documented.

@sibelius
Copy link

I think this should be in userland

this is too specific to be in a package

we can have another package that provide common offline behaviors

import { restoreOptimisticResponse } from 'common-offline-patterns'

that would handle this for apps that needs this

@morrys
Copy link
Owner

morrys commented Jul 17, 2019

maybe you wanted to refer this question to @wora/apollo-offline. Optimistic response layer is the way optimistic responses are handled by the apollo inmemory cache.

@wtrocki
Copy link
Author

wtrocki commented Jul 17, 2019

For exmaple:

  1. I'm creating new item when offline
  2. I'm editing the same item

With wora the second edit is sending an invalid id - it will send an optimistic response id.

@wtrocki
Copy link
Author

wtrocki commented Jul 17, 2019

Reason, why I'm asking, is that there are couple things that can be provided to enable wora to be the really comprehensive library. I was always dreamed of having a fully offline workflow. I really like @sibelius suggestion!

I have couple ideas to help here to make this better, but I will love to first know the motivation. Any reason why developers need to handle those cases in execute?

@sibelius
Copy link

I have more knowledge on relay

I think all mutations called when offline ("optmistic updates") are already persisted to relay store, so we don't need to restore them when application restarts, they are already there

what happens if that we rollback optimistic updates that fails to complete on server

More on this here https://dev.to/mattkrick/distributed-state-101-why-i-forked-facebook-s-relay-1p7d

for me offline events are much like optimistic events where the server event is very delayed

@morrys
Copy link
Owner

morrys commented Jul 17, 2019

@wtrocki this is my lack of documentation that I will update.

What I recommend to those who intend to handling offline is:
When a new item is created by request the id must be generated in the browser to use it in the optimistic response

with this simple requirement we obtain a remarkable resolution of problems and an efficiency in the processing of responses and data stores.

https://github.com/morrys/react-relay-offline#requirement

@wtrocki
Copy link
Author

wtrocki commented Jul 17, 2019

WOW, it is nice to see that relay actually gives such a feature. In Apollo, things look differently. Optimistic responses are not kept/persisted but I'm hoping to fix that so the behavior will be the same for Apollo/Relay! Thanks.

@morrys
Copy link
Owner

morrys commented Jul 17, 2019

on this subject I would like to talk to those who deal with apollo cache inmemory.

In a first version I also persisted the optimistic layer but the problem is another.

My approach to both relay and apollo is the same:

  • simulate optimistic insertion and recover changes to the backup store
  • I persistently enter the information in the store and save my sink changes

In relay it is possible, after restarting the application, to use the backup information to roll back the store (not in all use cases). In apollo it is not possible using native functions.

@morrys
Copy link
Owner

morrys commented Jul 17, 2019

react-relay-offline-useoffline

on the right is what you can do with the only information contained by offline mutations

for the moment it is present only in the example of relay project but I hope soon to include it also in the apollo one.

@morrys morrys added apollo-offline question Further information is requested labels Jul 17, 2019
@wtrocki wtrocki closed this as completed Jul 17, 2019
Repository owner deleted a comment from wtrocki Jul 17, 2019
@morrys morrys reopened this Jul 17, 2019
@wtrocki
Copy link
Author

wtrocki commented Jul 17, 2019

I think I can help with not possible on Apollo as we have done that in other library. Did you thought about having entire InMemory cache code inside and persisting all together?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apollo-offline question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants