If you are using Graphql you may already faced this issue where you have your own Graphql server and also needs to query data from a 3rd party API.
If this API is REST then no problem, you can just use fetch, Axios, etc. But what if this API is using Graphql? How can you tell your Apollo client if a query/mutation belongs to your backend or the other API?
I ran into this issue while developing my first Shopify App. I have Graphql on my backend and Shopify recently migrated to Graphql.
In this post, I will share how I managed to use the same Apollo client to communicate with both.
We can make this happen in 3 simple steps:
1- Create HttpLink to each endpoint
2- Configure Apollo client
3- finally, when you want to call a query or mutation you just need to pass the clientName to Apollo like this:
That's all! the magic happens inside ApolloLink.split. You give each query/mutation a "context" and Apollo figures out where to send it!
Happy coding ✌️