You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've run into what (I think) is undocumented behavior in the Apollo Client cache.
The issue is that when a field is returned as null due to an error in the resolvers chain and the errors policy is set to all, that field will end up cached as null and break other parts of the application that rely on the cache.
On my end I'd have believed that any response containing errors would avoid caching its responses to avoid caching potentially broken data or that we'd have an option to achieve said behavior but haven't been able to find it.
The issue is as follows when running 3 queries with errorPolicy: "all":
We ask for the following data: { me: { organization: { name, threads } } }
The first query brings back correct data.
The same query is then run but the resolver for threads fails, the error bubbles up all the way to organization, organization is returned as null and is cached.
Another query asks for { me: { organization: { name } } } running fetchPolicy: cache-first . Nothing should fail here, but because the user corresponding to me is found in the cache, the api is not hit and organization comes back as null.
Version run: 3.12.4
I've run into what (I think) is undocumented behavior in the Apollo Client cache.
The issue is that when a field is returned as
null
due to an error in the resolvers chain and the errors policy is set toall
, that field will end up cached asnull
and break other parts of the application that rely on the cache.On my end I'd have believed that any response containing errors would avoid caching its responses to avoid caching potentially broken data or that we'd have an option to achieve said behavior but haven't been able to find it.
The issue is as follows when running 3 queries with
errorPolicy: "all"
:We ask for the following data:
{ me: { organization: { name, threads } } }
threads
fails, the error bubbles up all the way toorganization
,organization
is returned as null and is cached.{ me: { organization: { name } } }
runningfetchPolicy: cache-first
. Nothing should fail here, but because the user corresponding tome
is found in the cache, the api is not hit andorganization
comes back as null.You can see a working example of this in here (open file
App.tsx
the preview running in port 5173): https://codesandbox.io/p/devbox/6w5n83Is there something that I'm missing, or how would you recommend handling this issue?
Thanks.
The text was updated successfully, but these errors were encountered: