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

feat(graphcache): Allow cache.resolve to return undefined for uncached fields #3333

Merged
merged 3 commits into from
Jul 25, 2023

Conversation

kitten
Copy link
Member

@kitten kitten commented Jul 25, 2023

Summary

This updates cache.resolve to return undefined for uncached fields.

This has two reasons:

  • Resolvers allow users to return undefined to signal a cache miss, however, this wasn't clear — both because of the documentation, and because cache.resolve itself never returns undefined. Hence, while it's popular to end a resolver in a cache.resolve call, this meant that a cache miss could never be caused on this field.
  • Not being able to return undefined meant that the Cache interface virtually had little to no ways of actually letting a user check whether a field was cached or not. By returning undefined this now becomes clear

This isn't considered a breaking change since it shouldn't alter prior behaviour significantly:

  • A user may now correctly see a cache miss, where before they accidentally didn't cause one
    • However, manually returning null still retains the prior behaviour obviously
  • All methods now accept undefined, so the chainability is retained. When a method that was chainable receives undefined as its entity input, it will also typically return undefined, unless it's a write method.

Set of changes

  • Allow cache.resolve to return undefined
  • Update cache.link to better handle variable number of arguments
  • Allow Entity argument type in Cache to accept undefined
  • Update ensureLink to handle undefined values gracefully
  • Update docs to clarify that resolvers are allowed to return undefined

@kitten kitten merged commit 68d02c1 into main Jul 25, 2023
6 checks passed
@kitten kitten deleted the feat/cache-resolve-undefined branch July 25, 2023 16:11
@github-actions github-actions bot mentioned this pull request Jul 25, 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