Open henrywoody opened 3 years ago
We are observing this kind of issue too, but we can't figure out if is an error of client misconfiguration/code or it's the actual behaviour.
I am observing this too I think, or something that seems related at least, in a slightly different context. As it might be different, I opened a separate issue: #9205
Intended outcome:
When calling
refetch
(fromuseQuery
) thedata
anderror
values from previous attempts should be cleared.Actual outcome:
The
data
anderror
values are preserved after callingrefetch
. There is a bit of nuance to this though.If the initial query results in an error, the
data
isnull
(orundefined
) and theerror
value is populated, ifrefetch
is called and the query then succeeds, thendata
is updated anderror
is cleared. This seems to be the correct handling.If the a query (not necessarily the initial query) completes successfully,
data
is populated anderror
isnull
(good), ifrefetch
is then called and results in error,data
is left unchanged from before (I would expect to becomenull
/undefined
again) and theerror
is populated as expected. So far that is a mild issue and I can work around it. If thenrefetch
is called and completes successfully, neitherdata
norerror
is updated and no React rerender is triggered, leaving the application stuck. (Possibly this only happens when the second successful call returns the same data as the first successful call).How to reproduce the issue:
refetch
for that query so that it results in an error.refetch
again so that it completes successfully.Additionally: I've set the
fetchPolicy
to"network-only"
and theerrorPolicy
to"all"
.Also this seems to be pretty much the same issue as this one: https://github.com/apollographql/apollo-client/issues/2513
Versions
A bit of context
I am working on an authentication handler in React using a context to provide authentication details to various parts of the application. My server supports a
whoami
query, which returns aUser
object for the current user. When the application mounts, the query is run to check if the user is logged in. If the query runs successfully, then the user is logged in and they proceed to the authenticated part of the app. If the query results in an error, the user is shown the login page.When the user logs in or out, the context manager calls
refetch
on the output of theuseQuery
hook to update the storeddata
anderror
values.Alternate approaches
If this use-case is wrong or there is an option I'm missing to get the desired handling, please let me know.