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) - Implement RFC for optimistic behavior enhancements #750

Merged
merged 20 commits into from
Apr 24, 2020

Conversation

kitten
Copy link
Member

@kitten kitten commented Apr 24, 2020

Summary

This PR implements both recommendations from RFC #747.

These changes have been validated and tested so far against @frederikhors' unexpected behaviour reproductions in CodeSandboxes:

Set of changes

  • Convert dependencies data structure from Set<string> to type Dependencies = Record<string, true>
  • Keep track of optimistically updated dependencies (of type Dependencies)
  • Block refetching of operations that have active optimistic updates and keep track of them (see above)
  • Allow executePendingOperations to trigger refetch for previously blocked cache-and-network operations
  • Keep track of optimistic mutation that are pending at the same time, and flush their results simultaneously, also erasing the optimistically updated (i.e. blocked) dependencies at the same time

@changeset-bot
Copy link

changeset-bot bot commented Apr 24, 2020

🦋 Changeset is good to go

Latest commit: 2648544

We got this.

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

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 force-pushed the feat/optimistic-mutation-enhancements branch from c1c7e22 to 4c7cc93 Compare April 24, 2020 16:06
@kitten kitten force-pushed the feat/optimistic-mutation-enhancements branch from a32ef53 to 3cdb60b Compare April 24, 2020 16:19
@kitten
Copy link
Member Author

kitten commented Apr 24, 2020

Both new strategies seem to be working. It's pretty exciting how this makes both aspects of optimistic mutations (refetching while they're active, and settling with/without optimistic updates) more intuitive.

This branch only needs some new unit tests.

@kitten kitten force-pushed the feat/optimistic-mutation-enhancements branch from 3cdb60b to bc20f8a Compare April 24, 2020 16:25
The semaphore map isn't necessary anymore as all
optimistic mutation results are flushed at the same
time.
@kitten kitten changed the title (graphcache) - Implement optimistic refetch blocking (graphcache) - Implement RFC for optimistic mutation behavior enhancements Apr 24, 2020
@kitten kitten marked this pull request as ready for review April 24, 2020 16:41
Previously we called clearLayer when clearing an optimistic
mutation result batch, which may erase existing mutation
result data. This shouldn't be possible but we can account
for duplicate mutation results this way and also stop
exposing clearLayer.
@kitten kitten force-pushed the feat/optimistic-mutation-enhancements branch from 2215228 to 398254f Compare April 24, 2020 17:04
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.

The refactor paired with this is awesome

exchanges/graphcache/src/cacheExchange.ts Show resolved Hide resolved
exchanges/graphcache/src/cacheExchange.ts Show resolved Hide resolved
exchanges/graphcache/src/cacheExchange.ts Outdated Show resolved Hide resolved
exchanges/graphcache/src/cacheExchange.ts Show resolved Hide resolved
@kitten kitten changed the title (graphcache) - Implement RFC for optimistic mutation behavior enhancements (graphcache) - Implement RFC for optimistic behavior enhancements Apr 24, 2020
@kitten kitten merged commit 6871e9b into master Apr 24, 2020
@kitten kitten deleted the feat/optimistic-mutation-enhancements branch April 24, 2020 18:13
@frederikhors
Copy link
Contributor

Guys, as explained here I created a new CodeSandbox with an entire CRUD!

We can test on it this amazing work! (I'll in a few minutes, I'm on smartphone).

Thank you guys! 😄

@frederikhors
Copy link
Contributor

From the first tests everything seems to work!

🥳

@kitten
Copy link
Member Author

kitten commented Apr 27, 2020

This has been released in @urql/exchange-graphcache@2.4.0

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.

None yet

4 participants