API / Apollo Gateway Interview questions
How does Apollo Gateway compose a supergraph?
Composition can happen in two ways depending on setup, but the overall flow is the same:
- Gateway (or GraphOS, in managed mode) fetches each subgraph's SDL, either via the
_service {{ sdl }}introspection field (unmanaged/IntrospectAndCompose) or from GraphOS's registry (managed federation). - The composition algorithm merges the type definitions, validating for conflicts — mismatched field types, ambiguous ownership of shared fields not marked
@shareable, and so on. - If composition succeeds, it produces a supergraph schema that includes routing metadata: which subgraph owns which field, and how each entity's key fields tie subgraphs together.
- That supergraph schema feeds the query planner, which uses the routing metadata to build fetch plans for incoming operations.
In unmanaged mode this whole process re-runs on gateway startup (and optionally on a polling interval); in managed mode, GraphOS runs it centrally and simply pushes the finished supergraph schema down.
More Related questions...