feat(graphcache): Allow cache.resolve to return undefined for uncached fields #3333
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This updates
cache.resolve
to returnundefined
for uncached fields.This has two reasons:
undefined
to signal a cache miss, however, this wasn't clear — both because of the documentation, and becausecache.resolve
itself never returnsundefined
. Hence, while it's popular to end a resolver in acache.resolve
call, this meant that a cache miss could never be caused on this field.undefined
meant that theCache
interface virtually had little to no ways of actually letting a user check whether a field was cached or not. By returningundefined
this now becomes clearThis isn't considered a breaking change since it shouldn't alter prior behaviour significantly:
null
still retains the prior behaviour obviouslyundefined
, so the chainability is retained. When a method that was chainable receivesundefined
as its entity input, it will also typically returnundefined
, unless it's a write method.Set of changes
cache.resolve
to returnundefined
cache.link
to better handle variable number of argumentsEntity
argument type inCache
to acceptundefined
ensureLink
to handleundefined
values gracefullyundefined