How to handle caching when querying two endpoints with the same query and schema?

We use one Apollo client that splits traffic (using Apollo Link) between two endpoints A and B–essentially two graphql servers with the same data schema, just with different different data.

I have a scenario where I need to get data from the same data field from both endpoints. So I query A and then I query B with the same graphql query. However, the results from query B always returns the results from query A, because query A has cached the its results under the same key that query B would cache. Query B checks the cache first and returns early since it found data in the cache from query A.

I could work around it by making query B slightly different (an extraneous parameter like limit: 100 or something) or setting it to skip the cache check, but it’s not ideal.

I’m wondering if anyone else has encountered this before or have suggestions?

How are you deciding which endpoint the query goes to?

I’m using the ApolloLink.split function, testing a value in the Operation context.

Maybe instead of using ApolloLink.split you could have two entirely separate ApolloClient instances with separate caches. The useQuery hook has a client option that allows you to specify which client you want to use. Possible downside to this approach would be that the two caches won’t communicate with each other at all, they would be completely separate.

Thanks, I was hoping to keep using ApolloLink but it may be time to rethink its usage. Having two caches that don’t communicate with each other is fine for our use case.

Appreciate your help here.