I have a useQuery hook inside my component to get a list of people:
const { data, loading, error } = useQuery(GET_PEOPLE_LIST, {
fetchPolicy: 'cache-and-network',
})
Sometimes when I run this query my token may be expired and the apollo onError link is triggered to refresh the token and rerun the failed query:
const errorLink = onError(({ networkError, graphQLErrors, operation, forward }) => {
if (networkError && networkError.statusCode === 401) {
return fromPromise(refreshtoken()).flatMap(response => {
saveAccessToken(response.accessToken)
return forward(operation)
})
}
console.error(graphQLErrors)
})
In the network tab I can see that the first query failed with a status of 401, then a request for a new token is made and then the first query is executed again but at this moment the status is 200 and the list of people has been returned.
The problem is getting the data returned by this query. When I give console.log in the data, loading and error of this query I only get the values of the time that failed even though the new attempt was successful and returned the list of people correctly.
const { data, loading, error } = useQuery(GET_PEOPLE_LIST)
console.log({ data, loading, error })
How can I get useQuery values to update after retrying a failed query?
(React 17, @apollo/client 3.6.6)
I already tried returning a new Observable inside onError link, and also the RetryLink suggested in this answer, but no success. I also tried with the latest versions of @apollo/client.