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): Improve separation of API and owned data #3165

Merged
merged 10 commits into from
Apr 20, 2023
Merged

Conversation

kitten
Copy link
Member

@kitten kitten commented Apr 19, 2023

Resolves #3160

Summary

This prevents us from:

  • copying the incoming API data causing __typename to be applied to output data by default
  • reusing incoming API data and treating it as equivalent to Graphcache’s owned data

In short, we don't differentiate in the cacheExchange whether we're passing query() previous Graphcache data or API data. This data is then used to diff against the new result, reusing as much of it as possible when it's unchanged. It's also used to complete the output data when some cache resolution fails, to fall back to API data.

However, we shouldn't reuse this data blindly when it's API data, since that data can slightly differ and carry __typename fields even when those aren't specified in the selection set.

Set of changes

  • Replace originalVariables with better operations.set tracking
  • Stop copying original data when creating “owned” data
  • Only reuse original data when it's previously “owned” data, and otherwise consider it changed
  • Add “foreign data” flag to initDataState
  • Remove operations helper usage in cacheExchange and intead call initDataState and clearDataState manually
  • Clean up usage of operations/*

@kitten kitten marked this pull request as draft April 19, 2023 14:04
@kitten kitten changed the title Fix/owned data fix(graphcache): Improve separation of API and owned data Apr 19, 2023
@kitten kitten marked this pull request as ready for review April 19, 2023 15:26
@kitten kitten force-pushed the fix/owned-data branch 2 times, most recently from 300c633 to 0e6d901 Compare April 19, 2023 15:32
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.

Cached data bug after page navigation with next-urql + exchange-graphcache
2 participants