⬡ GraphQL Advanced

What is Apollo Federation v2 and how does the supergraph work?

Answer

Apollo Federation v2 is the industry standard for composing multiple GraphQL services (subgraphs) into a single unified API (supergraph). Architecture: each team owns a subgraph with its own schema and resolvers; the Apollo Router (Rust-based gateway) receives client queries, runs the query planner to determine which subgraphs to call and in what order, executes the plan (potentially fetching from multiple subgraphs in parallel), and merges results. Key directives: @key(fields: "id") (entity primary key — enables cross-service entity resolution), @shareable (field can be defined in multiple subgraphs), @override(from: "SubgraphName") (migrate field ownership between subgraphs), @provides/@requires (optimize resolver execution by pre-providing fields). Schemas are composed with the Rover CLI. Apollo GraphOS manages schema checks, schema registry, and usage analytics.