1

When composing a supergraph for Apollo Federation's gateway, you would create a .yaml config file with the routing urls to the subgraphs. Ex: https://github.com/apollographql/supergraph-demo/blob/main/subgraphs/inventory/inventory.js

//supergraph.yaml
subgraphs:
  inventory:
    routing_url: http://inventory:4000/graphql
    schema:
      file: ./subgraphs/inventory/inventory.graphql
  products:
    routing_url: http://products:4000/graphql
    schema:
      file: ./subgraphs/products/products.graphql
  users:
    routing_url: http://users:4000/graphql
    schema:
      file: ./subgraphs/users/users.graphql

In the example above, they are starting an Apollo server for each subgraph and composing a supergraph. Is it possible to compose a supergraph without starting Apollo servers and just including the local schemas?

Jsbbvk
  • 180
  • 2
  • 19

1 Answers1

1

You can. Following this tutorial: https://www.apollographql.com/blog/backend/using-apollo-federation-with-local-schemas/

Instead of using super and sub-graphs, use serviceList and conditionally build the data source.

const gateway = new ApolloGateway({
  serviceList: [
    { name: "products", url: "http://localhost:4002" },
    { name: "countries", url: "http://countries" },
  ],
  buildService: ({ url }) => {
    if (url === "http://countries") {
      return new LocalGraphQLDataSource(getCountriesSchema());
    } else {
      return new RemoteGraphQLDataSource({
        url,
      });
    }
  },
});
Jsbbvk
  • 180
  • 2
  • 19