What is Apollo Federation and how do subgraphs, gateways, and directives like @key and @extends work?
Answer
Apollo Federation is an architecture for building a distributed GraphQL API from multiple independent subgraphs. Each subgraph is a standalone GraphQL service that owns a portion of the schema. The Gateway (Apollo Router or @apollo/gateway) composes subgraphs into a unified supergraph and generates a query plan to fetch data from the right services. The @key directive designates the primary key fields of an entity: type User @key(fields: "id") { id: ID! name: String! }. The @extends keyword (Federation v1) or extend type (Federation v2) lets a subgraph reference and extend an entity owned by another service — e.g., the Reviews subgraph extending the User type to add reviews. The gateway uses reference resolvers (__resolveReference) to stitch data across services. Federation enables true team autonomy — each team deploys and iterates on their subgraph independently while the gateway automatically updates the unified API.
Previous
What are GraphQL enums?
Next
What is incremental delivery in GraphQL with @defer and @stream?
More GraphQL Questions
View all →- Advanced What is incremental delivery in GraphQL with @defer and @stream?
- Advanced How do you implement query cost analysis and rate limiting in a production GraphQL API?
- Advanced What is schema evolution and deprecation strategy in GraphQL?
- Advanced What is the Relay specification for GraphQL — Node interface, Connection/Edge pagination?
- Advanced How do you implement distributed tracing across GraphQL resolvers?