Federation helps GraphQL grow by letting many teams work together easily. It breaks a big API into smaller parts that fit well together.
Why federation scales GraphQL
type Product @key(fields: "id") { id: ID! name: String price: Float } extend type Query { product(id: ID!): Product }
The @key directive marks the unique field to identify an entity across services.
extend type lets you add fields to types defined in other services.
type User @key(fields: "email") { email: String! name: String } extend type Review { author: User }
type Product @key(fields: "upc") { upc: String! price: Float } extend type Inventory { product: Product quantity: Int }
This shows two services: one for products and one for reviews. They share the Product type using federation. The gateway lets clients ask for product info and reviews together.
# Service A: Product service type Product @key(fields: "id") { id: ID! name: String } extend type Query { product(id: ID!): Product } # Service B: Review service type Review { id: ID! body: String product: Product @provides(fields: "name") } extend type Product @key(fields: "id") { id: ID! @external name: String @external reviews: [Review] } # Gateway combines these services so clients query one API # Query example: # { # product(id: "1") { # name # reviews { # body # } # } # }
Federation lets teams own parts of the schema independently, improving collaboration.
It reduces the risk of one big schema becoming too complex to manage.
Common mistake: forgetting to mark keys or external fields, which breaks linking between services.
Federation splits a big GraphQL API into smaller, manageable parts.
It helps many teams work together without conflicts.
Clients get a single API that combines data from all services smoothly.