Using GraphQL federation to build a supergraph

Create a supergraph by federating two or more GraphQL APIs into one unified GraphQL API.

GraphQL federation is the concept of connecting two or more GraphQL APIs (subgraphs) into one unified GraphQL API (supergraph). Each backend team or domain can build and maintain its own subgraphs independently.

Federation is easier in GraphQL than with REST because the concept of linking types is naturally built into GraphQL. For example, the following query returns the same answer regardless of whether all the results are coming out of one graph, or many.

{
   customer (email: "john.doe@example.com) {
       name
       orders {
           createdOn
           delivery {
               status
               statusDate
           }
       }
   }
}

Types of Federation: Query-based and Object-based

API Connect Essentials has a very simple construct for federation: two subgraphs link together into a supergraph by connecting the data in one with a query in the other. This is known as query-based federation.

Apollo uses a different model for federation: the same object is constructed from two or more subgraphs. This is called object-based federation.

API Connect for GraphQL supports both types of federation:

  • You can build subgraphs in API Connect for GraphQL, or some other library or tool, and federate them in API Connect for GraphQL. The API Connect for GraphQL federation code is agnostic about how the subgraphs are built. For more information, see Federating subgraphs in API Connect for GraphQL.
  • You can build subgraphs in API Connect for GraphQL, or proxy subgraphs not built in API Connect for GraphQL, and then federate them in Apollo. API Connect for GraphQL generates all the right subgraph compatibility that Apollo federation needs. For more information, see Federating subgraphs in Apollo.