Can we run Apollo federation along with the monolithic GraphQL server

This is helpful, thanks! If you don’t want to add the federation spec to your monolith schema, or start using managed federation, then you have one more option: static composition with rover.

Instead of using serviceList to have the gateway fetch subgraph schemas and compose them at runtime, you can create a “supergraph schema” with a config file and a command:

subgraphs:
  monolith:
    routing_url: "doesnt matter, this will be a local graphql data source"
    schema: 
      file: monolith.graphql
  test:
    routing_url: http://localhost:5000
    schema:
      file: test.graphql
rover supergraph compose --config config.yaml > supergraph.graphql

Then remove the serviceList argument:

const gateway = new ApolloGateway({
  supergraphSdl: readFileSync('supergraph.graphql', 'utf-8'),
  buildService() { ... }
});

I’d still very much recommend managed federation in production so that the gateway can update to new versions of the subgraph schemas automatically. But this pattern works great in development.

1 Like