Chaining apollo retryLink and errorLink
Asked Answered
K

1

6

Should Apollo retryLink come before or after the errorLink? Some examples show it as before https://medium.com/@joanvila/productionizing-apollo-links-4cdc11d278eb#3249 while some show it after https://www.apollographql.com/docs/react/api/link/apollo-link-rest/#link-order.

Kingfisher answered 21/4, 2022 at 8:40 Comment(0)
R
4

It depends how you want your errorLink logic to work, from the docs

Additive composition involves combining a set of links into a serially executed chain

and the Error Link

is called after the GraphQL operation completes and execution is moving back up your link chain

so if you place the retryLink before the errorLink

ApolloLink.from([retryLink, errorLink])

the errorLink will also be executed with the retries once the respective result is traveling back up the chain, in other words (if you are using the default docs example), there should be a console log on every attempt and attempts.max console logs in total.

In case the order is flipped the errorLink will be called after the retryLink is complete and the result traveled all the way back up, so there should be 1 console log from the errorLink call.

Relucent answered 16/9, 2022 at 16:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.