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

fix(graphcache): Allow partial optimistic results #3264

Merged
merged 4 commits into from
Jun 12, 2023

Conversation

kitten
Copy link
Member

@kitten kitten commented Jun 12, 2023

Summary

We basically had some logic that would allow writes to be incomplete, however, this didn't apply to optimistic results, which would always cause cached fields to be deleted. Furthermore, in production, partial results will always lead to cached values being deleted from the cache.

Instead, we can apply a better heuristic which only triggers the warning when a field is missing from the cache, but always allow writes to continue, no matter whether values are set or not.

This should in theory be safe, since we're moving potential errors over to reading from the cache.

This also adds a change which makes optimistic mutations read previous keys and __typename fields from the cache to complete mutation results from prior cache results. This should tremendously help the developer experience of having to create these functions.

Set of changes

  • Allow continue to be applied to undefined field values
  • Include ctx.optimistic in the above check
  • Update a test accordingly which checks for console.warns
  • Only trigger a warning if the field isn't cached
  • Auto-fallback to __typename from cached values
  • Auto-fallback to keys from cached links

@kitten kitten merged commit 008c61b into main Jun 12, 2023
@kitten kitten deleted the fix/partial-optimistic-updates branch June 12, 2023 22:51
@github-actions github-actions bot mentioned this pull request Jun 12, 2023
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.

1 participant