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 OptimisticNormalizedCache and API to write/rollback #607

Merged
merged 2 commits into from
Aug 4, 2017

Conversation

sav007
Copy link
Contributor

@sav007 sav007 commented 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 #583

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 sav007 force-pushed the feature-583/optimistic-cache branch from 89d9db5 to 21426e0 Compare August 3, 2017 03:07
@BenSchwab
Copy link
Contributor

BenSchwab commented Aug 3, 2017

Maybe I'm missing something, but does the following work:

Current key value (not in optimisitc cache): A -> 0
Optimistic update 1 A -> 1
Optimistic update 2 A -> 2
rollback optimistic update 2:
expect A -> 1, but it seems that rolling back 2 would remove the A from the optimistic cache, forgetting about update 1, which is still pending and valid.

Granted, the whole concept of racing contradicting mutations seems problematic to begin with.

@sav007
Copy link
Contributor Author

sav007 commented Aug 3, 2017

@BenSchwab yes that is correct, updates with version 2 will override updates with version 1. And when we rollback the version 2 it will rollback all. This case will happen only when second query was faster than the first one.

In order to support this case I guess we need to keep the whole history of changes for all records in mem cache. I think for now we can keep this simple version of implementation, and I will think how we can solve this case.

Copy link
Contributor

@BenSchwab BenSchwab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, well this looks neat.
Is the next part exposing this as part of the ApolloMutationCall for convenience?

@sav007
Copy link
Contributor Author

sav007 commented Aug 3, 2017

@BenSchwab Yeah, it will be almost similar to JS: ApolloMutationCall.optimisticUpdates(...)

@sav007 sav007 merged commit cab3313 into apollographql:master Aug 4, 2017
@sav007 sav007 deleted the feature-583/optimistic-cache branch August 4, 2017 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants