How to call remote GraphQL API from another Apollo GraphQL service

How to call remote GraphQL API from another Apollo GraphQL service

1 Like

@Neha_Tiwari can you share a few more details outlining what you would like to do? What Apollo GraphQL service would you like to call an API from?

We have RestDataSource to call the rest API from a GraphQL service. Do we have any such thing available to call a GraphQL service from another GraphQL service (without using federation)? Design is as follows


Apollo doesn’t currently provide a pre-built data source for this, but one option is to create a custom data source that uses the core Apollo Client library! Most of the Apollo Client docs focus on React, but you can see a basic generic JS query in the Apollo Client getting started article, and the core functions are documented here.

Making graphql calls from a federated graphql service to another federated graphql service sounds like an anti-pattern. Recommend making use of federation for this use case. You have a few oprions here.

  1. Return only min data (key field) needed to hydrate your type from Service B so that gateway can resolve the rest of the fields from Service A.
  2. Use requires directive. If a field amount in Service B requires a field weight from Service A, adding the @requires(fields: "weight") directive on the weight field should work as expected. Gateway will first resolve the weight field from Service A and then pass it to Service B.
  3. Make Service B a REST API.