urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.61k stars 449 forks source link

fix(graphcache): Allow partial optimistic results #3264

Closed kitten closed 1 year ago

kitten commented 1 year ago

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