API / Apollo Gateway Interview questions
How do you configure Apollo Gateway with Apollo Server?
You construct an ApolloGateway instance and pass it to ApolloServer in place of a local schema. In development, it's common to use IntrospectAndCompose to compose locally from a static list of subgraph URLs; in production, managed federation is preferred instead.
const { ApolloServer } = require('@apollo/server'); const { ApolloGateway, IntrospectAndCompose } = require('@apollo/gateway'); const gateway = new ApolloGateway({ supergraphSdl: new IntrospectAndCompose({ subgraphs: [ { name: 'products', url: 'http://localhost:4001/graphql' }, { name: 'reviews', url: 'http://localhost:4002/graphql' }, ], }), }); const server = new ApolloServer({ gateway });
For managed federation in production, you'd instead omit supergraphSdl and set APOLLO_KEY / APOLLO_GRAPH_REF environment variables so the gateway pulls the composed supergraph from GraphOS's Uplink service automatically.
More Related questions...