I want to implement a way to switch over different links based on the context set in graphql query. What I did so far is something like this which is working fine but doesn't seem to be a nice solution over time.
const link = ApolloLink.from([
HandlerLink1,
HandlerLink2,
ApolloLink.split(
operation => operation.getContext().service === "x",
LinkX,
ApolloLink.split(
operation => operation.getContext().service === "y",
LinkY,
ApolloLink.split(
operation => operation.getContext().service === "z",
LinkZ,
LinkN
)
)
)
]);
Is there any better way rather than doing it nested?