Federating an external GraphQL Resource

Hey Apollo Community!

One of the resources of our federated GraphQL microservice architecture (apollo gateway + subgraphs) is another external GraphQL-API. This external API does not support federation. Now we were wondering if it is somehow possible to integrate this external GraphQL-API in a nice way. Is it e.g. reasonable to build a subgraph which forwards requests to this external GraphQL-API? If so how would you extract the actual payload intended for the external API from the federated schema?

Is there another way to do it?

Thank you for your suggestions!

Hello! I believe what you describe is indeed reasonable, building your own subgraph that populates fields using data from the external GraphQL API. In this sense, the external API is similar to a REST API, database, or any other data source that a subgraph might connect to when populating its data.

Your subgraph’s schema definitions could correspond to the types and fields defined in the external API, but it definitely doesn’t need to exactly if your resolvers handle any necessary mapping. You can also leave out any parts of the external API you don’t care about. In any case, you might want to namespace any type definitions that correspond to external API types (e.g., ExternalAPIUser instead of User) to prevent undesirable collision with your own types.

Thanks for your reply @StephenBarlow !
When we build this external-GraphQL adapter subgraph how exactly would this “resolvers handle any necessary mapping” happen? The way i understand it: We need to extract the query from the info object, transform it and then send it to the external API. But we are stuck at the first step, how would you extract the query from the info object without relying on string manipulation? Are there frameworks or other methods that we are missing?

Thanks for your suggestions!