(graphcache) - Fix uncached GraphQLError fields making it impossible to get first API result #1367
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.
This is a follow-up for #1356
Summary
The #1356 change introduced behaviour that prevents
null
values from fields that have errored and are associated withGraphQLError
from being cached. This caused a regression where when we "read-back" results from the cache that have just arrived from the API these fields would cause a cache miss:https://github.com/FormidableLabs/urql/blob/6a687091b67dc3d0ee78353ca79b0aa401ba983c/exchanges/graphcache/src/cacheExchange.ts#L237-L243
We can prevent this by also tracking errored fields in the
query
and ignoring these uncached fields there too by replacing them withnull
while we still have access to theGraphQLError
s.This is preferable to other solutions as we've gotten rid of comparing the cached result to the API result in #1196 as we had trouble differentiating between
null
selection sets from previous selections andnull
values from the API result.No changeset is needed since the PR is unreleased.
Set of changes
null
'd fields due toGraphQLError
s from an APIctx.__internal.path
in all environments inquery
tooquery
and set the field tonull
if it does have an error