Node.js › GraphQL
How would you implement GraphQL schema stitching or federation to compose a single unified GraphQL API from multiple underlying microservices?
AdvancedAnswer
Apollo Federation lets multiple independent GraphQL services (subgraphs), each owning a specific part of the overall schema, be composed into a single unified graph exposed to clients through a gateway -- a type can even be extended across service boundaries (like a Products service defining a Product type, and a Reviews service adding a 'reviews' field to that same Product type), letting each team independently own and deploy their portion of the schema while clients query the whole thing as if it were one seamless API.
# Products subgraph
type Product @key(fields: "id") { id: ID!, name: String! }
# Reviews subgraph, extending the Product type defined elsewhere
type Product @key(fields: "id") @extends {
id: ID! @external
reviews: [Review!]!
}Real-world example A large e-commerce company with separate teams owning Products, Reviews, and Inventory each maintain their own independently deployable GraphQL subgraph, composed via Apollo Federation's gateway into a single unified API that frontend teams query without needing to know or care which underlying microservice actually owns each specific field.