I work with apollo client, implimenting auth with jwt. I catch the error from back when i try do smt when my token is expired , refresh tokens and then resend request. It work like it should, but my component does not rerender, new request sends, i get data, but my component still show error. How can i rerender my component with new data?
const errorLink = onError(
({ graphQLErrors, networkError, operation, forward }) => {
if (graphQLErrors) {
graphQLErrors.forEach(({ message, locations, path }) => {
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
);
// Handle specific errors
if (message === "jwt expired") {
Refreshtoken()
.then((r) => forward(operation))
.catch((e) => console.log("@1", e));
}
if (
message ===
"Access denied! You don't have permission for this action!"
) {
// Call Refreshtoken function or perform any other desired action
fromPromise(
Refreshtoken()
.then((r) => {
getNewToken("access-token").then((r) => {
operation.setContext({
headers: {
authorization: `Bearer ${r}`,
},
});
console.log("operation", operation.getContext());
return toPromise(forward(operation)) });
})
.catch((e) => console.log("@", e))
);
}
//get new token from cookies
});
}
if (networkError) {
console.log("@");
console.log(`[Network error]: ${networkError}`);
}
}
);
Code from component
const { loading, data } = useQuery(
GET_ANIME,
{ variables: { slug: params.slug }, fetchPolicy: 'no-cache', }
);
I expect my component will rerender with correct data after i resend request and get data, no error.
I tried change onError code, change cache-policy but it doesnt work for me.