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

(graphcache) - Fix edge cases in operation ordering #638

Merged
merged 5 commits into from Mar 18, 2020

Conversation

kitten
Copy link
Member

@kitten kitten commented Mar 18, 2020

Resolve #633

Summary

Previously the cacheExchange code had trouble with results coming in "spontaneously". It also erroneously created optimistic layers for queries and mutations at the wrong time. createLayer exacerbated the issue by not being idempotent.

On a side note, sorry for commutativity causing issues for some of you! But we believe that it'll eventually strengthen our caching guarantees and make all caching operations more predictable in the face of timing changes. So we hope that after ironing out its flaws and adding more tests that it'll be a great addition!

Set of changes

  • Move optimisticUpdate logic into the later prepareForwardedOperation to avoid further mistakes
  • Fix noopDataState(store.data, operation.key, true /* meaning optimistic */); from being called for all queries and mutations and replace it with reserveLayer
  • Call reserveLayer for results that came in without a reservation (subscriptions need this, but queries may also need it)
  • Fix createLayer not being idempotent

- Ensure that reserveLayer can be called repeatedly
- Apply optimistic updates later in the chain
- Add last-chance reserveLayer to every query/subscription
@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2020

🦋 Changeset is good to go

Latest commit: 11ca879

We got this.

This PR includes changesets to release 1 package
Name Type
@urql/exchange-graphcache Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kitten kitten changed the title WIP: Fix edge cases in operation ordering and accidental optimistic layers Fix edge cases in operation ordering and accidental optimistic layers Mar 18, 2020
@kitten kitten marked this pull request as ready for review March 18, 2020 20:59
Copy link
Collaborator

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

Saving size and fixing bugs, count me in! Nice one

@kitten kitten changed the title Fix edge cases in operation ordering and accidental optimistic layers (graphcache) - Fix edge cases in operation ordering Mar 18, 2020
@kitten kitten merged commit 4254957 into master Mar 18, 2020
@kitten kitten deleted the fix/commutative-idempotency branch March 18, 2020 21:35
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.

cache.writeFragment and commutative updates
2 participants