Skip to content

fix(graphcache): Improve separation of API and owned data#3165

Merged
kitten merged 10 commits intomainfrom
fix/owned-data
Apr 20, 2023
Merged

fix(graphcache): Improve separation of API and owned data#3165
kitten merged 10 commits intomainfrom
fix/owned-data

Conversation

@kitten
Copy link
Copy Markdown
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 requested a review from JoviDeCroock April 19, 2023 14:04
@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