-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
forward in onError link doesn't send any requests #9609
Comments
@frimuchkov Did you find a way to fix this ? |
@frimuchkov Problem solved on my side, it was just a problem of order in |
@magrinj have you solved it with chaning order of links? |
@frimuchkov Yes in my case it was the issue, I've 3 links ApolloLink.from([errorLink, authLink, httpLink]); // -> Not working The correct order is: ApolloLink.from([authLink, errorLink, httpLink]); // -> Working In the wrong order, |
@frimuchkov 👋 Let us know if the suggestions from @magrinj helped your case. Thanks for the guidance @magrinj, it's appreciated. 🙏 |
i still face the problem when token get expired const BASE_URL = process.env.NEXT_PUBLIC_API_URL;
const httpLink = new HttpLink({ uri: BASE_URL });
const authMiddleware = new ApolloLink((operation, forward) => {
// add the authorization to the headers
operation.setContext(({ headers = {} }) => ({
headers: {
...headers,
authorization: `bearer ${getLocalAccessToken()}`,
},
}));
return forward(operation);
});
const handleError = onError(({ graphQLErrors, networkError, operation, forward }: any) => {
if (graphQLErrors) {
for (let err of graphQLErrors) {
switch (err.extensions.code) {
case 'UNAUTHENTICATED':
console.log('==UNAUTHENTICATED==');
refreshToken().then(({ data }: any) => {
const { token, refresh } = data.refreshToken;
updateLocalAccessToken(token);
updateLocalRefreshToken(refresh.refreshToken);
const oldHeaders = operation.getContext().headers;
operation.setContext({
headers: {
...oldHeaders,
authorization: `bearer ${token}`,
},
});
return forward(operation);
});
}
}
}
if (networkError) {
store.dispatch(showAlert('Connection Failed, please try again!', 'error'));
}
});
const client = new ApolloClient({
cache: new InMemoryCache(),
link: ApolloLink.from([authMiddleware, handleError, httpLink]),
}); |
@moeldeeb98 - I had similar code to yours, using Firebase for my client side token and verifying it on the backend with Firebase admin. After returning an "Observable" from apollo/client, the request was forwarded. The code is courtesy of stackoverflow users Igor Lamos and Dan Dascalescu
|
Hello everyone, I encountered a similar issue, forget forward instead use axios. const errorLink = onError(({ graphQLErrors,networkError, operation }) => {
}); |
Hi! We try to refetch network errors but looks like forward doesn't work and doesn't emit new request.
The text was updated successfully, but these errors were encountered: