How to use these 4 all together in apollo client in Apollo refresh token

37 Views Asked by At
const client = new ApolloClient({
cache: new InMemoryCache({ possibleTypes }),
link: from([authLink,refreshTokenLink,httpLink, errorLink]),
});

This is my apollo code and on these these link: from([authLink,refreshTokenLink,httpLink]) are working fine on adding errorLink that is not calling. Also tried with concat and change the array values but it's not working also let me know if there is any working example.

1

There are 1 best solutions below

0
On

httpLink is a "terminal link" - it won't call any link behind it. So ordering is important here!

Move your errorLink before the httpLink - generally, a link can only see the results of what comes behind it, so it wouldn't be useful at the end.

With your current odering, it goes

  • authLink calls refreshTokenLink (can pass things into refreshTokenLink and httpLink and see what they return)
  • refreshTokenLink calls httpLink (can pass things into httpLink and see what it returns)
  • httpLink makes a request and returns the result.

You need to go

from([authLink,refreshTokenLink,errorLink,httpLink]) 

because for the errorLink to be any useful, it needs to see the errors returned from the httpLink.