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

Introduce Optimistic updates for mutations #583

Closed
sav007 opened this issue Jul 22, 2017 · 2 comments
Closed

Introduce Optimistic updates for mutations #583

sav007 opened this issue Jul 22, 2017 · 2 comments

Comments

@sav007
Copy link
Contributor

sav007 commented Jul 22, 2017

The problem: in most cases the result of mutations are well known even before waiting for server response. The idea behind optimistic updates are pretty straight forward, to be able specify optimisticResponse for mutation operation that will be temporary saved into memory cache before network response arrives.

Proposal: introduce the layer that is basically separate instance of ApolloStore for optimistic updates only and that based on mem cache. Any queries that try to read response from cache will first hit ApolloStore with optimistic updates and if it can't resolve cache response then will hit regular ApolloStore with normalized cache. The rollback mechanism for optimistic updates should remove them in case if mutation succeed or failed.

http://dev.apollodata.com/react/mutations.html#optimistic-ui
https://dev-blog.apollodata.com/mutations-and-optimistic-ui-in-apollo-client-517eacee8fb0

@sav007
Copy link
Contributor Author

sav007 commented Jul 22, 2017

@BenSchwab @digitalbuddha @martijnwalraven I'm going to start working on this feature so if you have any thoughts, comments pls share

@BenSchwab
Copy link
Contributor

I was thinking of a similar approach! Sgtm

sav007 added a commit to sav007/apollo-android that referenced this issue Jul 30, 2017
Refactor the way how normalized caches connected with each other.
Now, instead of having primary and secondary caches only, we allow user to build a chain with arbitrary number of cache instances.

Logic of `loadRecord`/`merge`/ `clearAll`/ `remove` records from the chain of caches will be the same as it was before for `LruNormalizedCache` with primary and secondary caches.

Part of apollographql#583

Next step is to create OptimisticUpdateCache based on Lru and make it to be the first cache in the chain
sav007 added a commit to sav007/apollo-android that referenced this issue Aug 3, 2017
Introduce `OptimisticNormalizedCache` to be always used as first layer in a chain
Introduce `ApolloStore` API to write/rollback optimistic updates
Some small refactoring related to `RecordFieldJsonAdapter` that required only for SQL cache

Part of apollographql#583
sav007 added a commit to sav007/apollo-android that referenced this issue Aug 3, 2017
Introduce `OptimisticNormalizedCache` to be always used as first layer in a chain
Introduce `ApolloStore` API to write/rollback optimistic updates
Some small refactoring related to `RecordFieldJsonAdapter` that required only for SQL cache

Part of apollographql#583
sav007 added a commit to sav007/apollo-android that referenced this issue Aug 7, 2017
Provide public API to create mutation call with optimistic updates.
Wrap network invokation inside `ApolloCacheInterceptor` with write / rollback optimistic updates block.
Fix issue with `OptimisticNormalizedCache#mergeOptimisticUpdate` returns empty set for first time cached records.
Introduce test watcher and mutation with optimistic updates.

Part of apollographql#583
sav007 added a commit to sav007/apollo-android that referenced this issue Aug 7, 2017
Provide public API to create mutation call with optimistic updates.
Wrap network invokation inside `ApolloCacheInterceptor` with write / rollback optimistic updates block.
Fix issue with `OptimisticNormalizedCache#mergeOptimisticUpdate` returns empty set for first time cached records.
Introduce test watcher and mutation with optimistic updates.

Part of apollographql#583
sav007 added a commit to sav007/apollo-android that referenced this issue Aug 7, 2017
Provide public API to create mutation call with optimistic updates.
Wrap network invokation inside `ApolloCacheInterceptor` with write / rollback optimistic updates block.
Fix issue with `OptimisticNormalizedCache#mergeOptimisticUpdate` returns empty set for first time cached records.
Introduce test watcher and mutation with optimistic updates.

Part of apollographql#583
@sav007 sav007 added this to the 1.0.0 milestone Aug 8, 2017
sav007 added a commit to sav007/apollo-android that referenced this issue Aug 9, 2017
Rolling back optimistic updates is smart now, it keeps the history of record updates.
If mutation finished it's execution it rolls back only its version of the record and keeps the rest versions for still running mutations.

Closes apollographql#583
sav007 added a commit to sav007/apollo-android that referenced this issue Aug 9, 2017
Rolling back optimistic updates is smart now, it keeps the history of record updates.
If mutation finished it's execution it rolls back only its version of the record and keeps the rest versions for still running mutations.

Closes apollographql#583
sav007 added a commit to sav007/apollo-android that referenced this issue Aug 9, 2017
Rolling back optimistic updates is smart now, it keeps the history of record updates.
If mutation finished it's execution it rolls back only its version of the record and keeps the rest versions for still running mutations.

Closes apollographql#583
sav007 added a commit to sav007/apollo-android that referenced this issue Aug 10, 2017
Rolling back optimistic updates is smart now, it keeps the history of record updates.
If mutation finished it's execution it rolls back only its version of the record and keeps the rest versions for still running mutations.

Closes apollographql#583
sav007 added a commit to sav007/apollo-android that referenced this issue Aug 10, 2017
Rolling back optimistic updates is smart now, it keeps the history of record updates.
If mutation finished it's execution it rolls back only its version of the record and keeps the rest versions for still running mutations.

Closes apollographql#583
sav007 added a commit that referenced this issue Aug 10, 2017
Rolling back optimistic updates is smart now, it keeps the history of record updates.
If mutation finished it's execution it rolls back only its version of the record and keeps the rest versions for still running mutations.

Closes #583
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants