In my GraphQL server I want to fetch data from a third party GraphQL endpoint and return the same data from it’s resolver. Is schema delegation used to achieve this?
Hi @ravish-goel , there are a couple options you have here. You can accomplish this with Apollo Federation and you can combine the remote 3rd party endpoint. You can try this out with rover dev
or a Cloud Router instance.
Using the Cloud Router - use this if you have your GraphQL server hosted
-
Create your supergraph with GraphOS. You can use the 3rd party endpoint as your first graph
Note: you might need to configure your cloud router for authentication rules if the 3rd party API requires it - Navigate to the “Subgraphs” tab in Apollo Studio and add your GraphQL server (see image)
- Once you’ve added your subgraph, head to the Apollo Explorer tab (the play button above the subgraphs tab) and try running a query across subgraphs
Using rover dev
- use this if your GraphQL server is only available locally (currently in development)
- Install
rover
- In a terminal window, run
rover dev --name=3rd-party --url=https://3rd-party.com/api/graphql
(make sure to replace the URL with your 3rd party endpoint)
Note: if the 3rd party endpoint doesn’t support introspection, you can use a local schema file and add --schema=schema.graphql to the above command. You may also need to configure authentication forrover dev
if the 3rd party API requires it - In a new terminal window, run
rover dev --name=my-service --url=http://localhost:4000
(make sure to replace the URL with your locally running GraphQL server - Open up http://localhost:3000 and try running a query across your graphs.
I hope this helps. If you want to dive into it deeper or walk through an example, we started up an Apollo Discord server and you can ping me (@watson) to talk more. Hope to see you there!