From One Graph to Many: Federation's Model
Schema Stitching: the Gateway That Became a BFF Again
The first way to get one graph out of many GraphQL services was schema stitching in graphql-tools. The gateway introspected each remote schema and merged them. Then it relied on hand-written delegation resolvers to connect the types. For example, a resolver on Row.videos that takes the video ids from the personalization service and calls video(id:) on the catalog service. Under a stitching gateway, the TV home page looks like this:
- The personalization, catalog and member services each expose their own root fields.
- The gateway team writes the join code, for example "a
Rowhasvideos, and to get them, call catalog with these ids". - Every new cross-service edge is a gateway deploy, owned by the gateway team.
That is the "monolith in the middle" from the BFF era part again, now written in GraphQL. The joins are orchestration logic that belongs to neither a screen nor an entity, and it has piled up in one shared tier. Apollo added a deprecation notice for stitching to graphql-tools in 2019, alongside the launch of Apollo Federation (May 2019). The core difference is who declares the join. Under federation, the catalog team declares that Video can be looked up by id, and every other subgraph can then return a bare Video { id } reference. No central code is needed.
Federation 1 → 2: From "Extend" to Shared Ownership
Federation 1 had an origin model. Each entity was defined in exactly one service. Every other service had to write extend type Member @key(fields: "id") and re-declare id as @external. Java and other SDL-first stacks without extend used @extends instead. Value types, meaning non-entity types, had to be defined identically everywhere.
Federation 2 (GA April 2022, opt-in through @link(url: "https://specs.apollo.dev/federation/v2.x")) dropped the origin model, per Apollo's versions page. Now "any number of subgraphs" can define the same entity and add fields to it without extend. In exchange, a field may be resolved by only one subgraph unless it is explicitly marked @shareable. This single-owner default is the version of the organizing line that composition enforces: one entity, many contributors, one owner per field.
The Entity Contract: @key, _entities, Reference Resolvers
This is how the home page's Member is split across three subgraphs. Each one owns different fields and none of them imports another:
members subgraph (profile service)
extend schema @link(url: "https://specs.apollo.dev/federation/v2.7",
import: ["@key", "@shareable", "@override", "@inaccessible"])
type Member @key(fields: "id") {
id: ID!
maturityLevel: MaturityLevel
language: String!
avatar: Avatar
}membership subgraph
type Member @key(fields: "id") {
id: ID!
plan: Plan!
entitlements: [Entitlement!]!
}personalization subgraph: owns Page/Row, only *references* Video and Member
type Query { homePage(profileId: ID!): Page }
type Page { member: Member! rows: [Row!]! }
type Row { title: String! videos: [Video!]! }
type Member @key(fields: "id", resolvable: false) { id: ID! }
type Video @key(fields: "id", resolvable: false) { id: ID! }resolvable: false says "I can hand out Video { id } stubs but I have no reference resolver for Video". Composition then leaves this subgraph out of _Entity for Video, and the planner never routes a Video lookup here.
The runtime contract is two fields that every subgraph must expose, defined in the subgraph spec:
scalar _Any # a JSON "representation": __typename + @key fields
union _Entity = Member | Video # generated: every type with a resolvable @key
type _Service { sdl: String! }
extend type Query {
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}_service.sdl returns the subgraph's SDL including federation directives. Plain introspection drops directives, so this field is how tooling reads the @keys. _entities is the only field the router uses to join, and a call to it looks like this:
router → membership subgraph (one HTTP request)
query($representations: [_Any!]!) {
_entities(representations: $representations) {
... on Member { plan { tier } entitlements { kind } }
}
}
# variables
{ "representations": [ { "__typename": "Member", "id": "42" } ] }Three details of this contract have effects in production:
| Order | The result list must match the input position for position. The router joins results back by index, not by id. |
|---|---|
| Nullability | [_Entity]!: each item can be null. One unknown member becomes null plus an error in its slot, and the other items still resolve. |
| Resolver | Each type gets a reference resolver (__resolveReference in Apollo Server, @DgsEntityFetcher in Netflix DGS) that runs once per representation. |
The last point matters more than it looks. The router sends a whole list of representations in one request, but the subgraph library then calls your reference resolver N times. The request is batched at the network layer. Inside the subgraph, backend calls are only batched if you put a DataLoader behind the reference resolver (see What GraphQL changes). A batched _entities call without a DataLoader is still N+1, just one hop further down. How many representations the router puts in each call, and whether it removes duplicates, is the query planner's job (see The query planner).
The Directive Toolbox
Each directive is a statement to the planner about where data can come from. The cost column is what the statement adds at runtime:
| Directive | What it tells composition / planner | Home-page use | Runtime cost |
|---|---|---|---|
@key(fields, resolvable)2.0; interfaces 2.3 | This type is an entity, and here is its lookup key. It is repeatable (@key(fields: "id") @key(fields: "isbn")) and supports compound keys ("id region { code }"). | Member by id in three subgraphs | An _entities hop whenever a selection crosses subgraphs |
@shareable2.0 | More than one subgraph resolves this field, so the planner may pick any of them. Key fields are shareable implicitly. | Video.title in catalog and (denormalized) personalization | None. It can save hops, and it adds a correctness risk (trap below). |
@external | "I declare this field but don't normally resolve it". Only meaningful together with @requires or @provides. | Declares runtimeSeconds in viewing-history | None on its own |
@requires(fields) | To resolve this field, first fetch those fields from their owner and pass them in with the representation. Since 2.1.2 the required fields can take static arguments. | Video.remainingSeconds @requires(fields: "runtimeSeconds") | One extra sequential hop for every @requires chain (see The query planner) |
@provides(fields) | On this path, I can return these fields of a referenced entity myself. | Row.videos: [Video!]! @provides(fields: "title") | Removes a hop, but only when every selected field is covered |
@override(from, label)2.0; label 2.7 | This field is now resolved here instead of in subgraph from. With label: "percent(n)", only some requests are moved. | Moving Member.maturityLevel off the legacy shim (see The migration playbook) | Plan-cache entries double per label in play |
@inaccessible2.0 | Keep the field in the supergraph but remove it from the client-facing API schema. | A new Member.householdId before all subgraphs define it | None. Clients get a validation error if they select it. |
@interfaceObject2.3 | This subgraph adds fields to every implementation of an entity interface without knowing the implementations. | Artwork on an abstract Title (movie / show) | The planner may add a hop to resolve the concrete __typename |
@context / @fromContext2.8 | Pass a value from an ancestor down to a descendant field's argument. | Member's language → Video.artwork(lang:) | May add a fetch for the ancestor value |
Other directives belong to the tiers that enforce them rather than to the join model. @authenticated / @requiresScopes (2.5) and @policy (2.6) are enforced by the router before a subgraph is ever called (see Where the BFF's jobs go). @cost / @listSize (2.9) feed demand control (see Operating the gateway). @tag feeds contracts, and @composeDirective carries custom directives through to the supergraph.
@requires and @provides: two directions of the same trade
The two directives trade in opposite directions:
@requirestakes autonomy and pays for it with latency. Viewing-history computesremainingSecondswithout calling catalog itself, but the router must fetchruntimeSecondsfrom catalog first. That makes the dependency visible in the plan and removes it from the service mesh, and it adds a hop.@providestakes latency and pays for it with consistency. Personalization already stores titles in its row index, so a home page that selects onlyvideos { id title }never calls catalog. The cost is that personalization now serves a copy of catalog's data.
# viewing-history subgraph
type Video @key(fields: "id") {
id: ID!
runtimeSeconds: Int! @external
remainingSeconds: Int! @requires(fields: "runtimeSeconds") # member from auth context
}At runtime, viewing-history's reference resolver receives { "__typename": "Video", "id": "80100172", "runtimeSeconds": 6480 }. The required field arrives inside the representation, filled in by the router.
@override and Progressive Override: Moving a Field
@override is federation's strangler-fig primitive (see the Netflix Architecture guide's Strangler Fig Migration part). The unit that moves is a field, not an endpoint. While the legacy shim subgraph (see The migration playbook) still serves Member.maturityLevel, the members team adds:
type Member @key(fields: "id") {
id: ID!
maturityLevel: MaturityLevel @override(from: "legacy", label: "percent(5)")
}Composition writes both claims into the supergraph as @join__field(graph: MEMBERS, override: "legacy", overrideLabel: "percent(5)") plus @join__field(graph: LEGACY, overrideLabel: "percent(5)"), which needs join spec v0.4 or later. To ramp up, you republish the subgraph with a new percentage; there is no router deploy. Rollback is also a republish. Once the label reaches 100, you delete the field from legacy and then drop the directive, in that order (migrate-fields docs). The planner cost, from the docs: "the number of query plans doubles for each unique label in the operation's 'path'". The router only counts labels the operation actually touches (the labels_per_operation_cache in the router's progressive_override plugin). Five concurrent migrations on the home-page path still means up to 25 = 32 plan variants for that one operation.
Composition: N Subgraph SDLs → One Supergraph
Composition runs before any traffic flows: in GraphOS whenever a subgraph publishes, or locally with rover supergraph compose. It is where the org chart gets type-checked (see Schema governance), and it produces two schemas. The supergraph schema is every type and field annotated with join__* routing metadata, and only the router reads it. The API schema is the supergraph with the federation machinery and every @inaccessible element removed, and it is the only schema clients ever see.
supergraph excerpt (abridged)
enum join__Graph {
MEMBERS @join__graph(name: "members", url: "http://members:4001/graphql")
MEMBERSHIP @join__graph(name: "membership", url: "http://membership:4002/graphql")
LEGACY @join__graph(name: "legacy", url: "http://tv-shim:4000/graphql")
}
type Member
@join__type(graph: MEMBERS, key: "id")
@join__type(graph: MEMBERSHIP, key: "id")
@join__type(graph: LEGACY, key: "id")
{
id: ID!
plan: Plan! @join__field(graph: MEMBERSHIP)
maturityLevel: MaturityLevel
@join__field(graph: MEMBERS, override: "legacy", overrideLabel: "percent(5)")
@join__field(graph: LEGACY, overrideLabel: "percent(5)")
}The merge rules follow from which direction data flows. Clients only read output types and write input types, so the rules are loose in one direction and strict in the other (composition rules):
| Element | Merge strategy | Why |
|---|---|---|
| Object (output) types | Union of fields | Each subgraph contributes its own fields |
| Input types, field arguments | Intersection | The router may send an input to any subgraph that defines it, so it can only accept what every one of them accepts |
| Enums | Union if output-only, intersection if input-only, exact match if both | The same read/write logic |
| Shared field nullability | Least restrictive wins (String! + String → String) | The supergraph can't promise non-null if any source can return null |
| Satisfiability | Every field must be reachable by every valid operation path | Apollo calls this the "most complex and most essential" rule. It guarantees the planner can always build a plan. |
A composition failure is safe: the publish is rejected and routers keep serving the last supergraph that composed. The dangerous case is a supergraph that composes successfully but carries wrong semantics, such as a conflicting @shareable or a bad @override. It is distributed to every router within seconds. That blast radius belongs to the Operating the gateway part.
Gateway → Router: the Runtime Changed Language Twice
| When | Runtime | What changed |
|---|---|---|
| May 2019 | @apollo/gateway (Node.js) + Federation 1 | The planner and executor ran inside an Apollo Server process |
| Nov 2021 | Federation 2 announced; license change | Federation 2 and Gateway 2.x moved to Elastic License v2, which forbids offering it "as a managed service". @apollo/subgraph stayed MIT. |
| Sep 22 2022 | Apollo Router v1.0 (Rust) | Apollo claimed "90% less variance in latency than the Apollo Gateway". The planner was still the JS one, embedded via Deno/V8. |
| Sep 2023 | Gateway v0.x end of life | Gateway 2.x still exists, but Apollo's docs "recommend using the GraphOS Router" in most cases |
| Router 1.49 → 1.59 | Native Rust query planner | Introduced in 1.49 and made the default in 1.59. Apollo reports a "10x median improvement" in planning time. |
| Router 2.x (2025) | JS planner removed | Fed 2.10+ requires Router ≥ 2.0 |
| July 2026 | Federation 2.15 (LTS) | Composition itself rewritten in Rust. It adds new validations, including invalid @override labels. |
For this guide, the important part is that the model above stayed the same through all of it: SDL directives, _entities, a supergraph. Netflix could build its own gateway on the same spec rather than run Apollo's (see Netflix's actual path), and DGS subgraphs expose _entities no matter which router calls them.
Beyond Apollo: the Composite Schemas Spec
Apollo Federation is a vendor specification, not a GraphQL Foundation standard. The Foundation's answer is the Composite Schemas spec, written by a subcommittee of the GraphQL Working Group (graphql/composite-schemas-spec). As of September 2026 its README still says "Stage 0: Preliminary". It has had no releases and can change before reaching Draft. The biggest design change is that there is no _entities. Entities are fetched through ordinary root fields marked @lookup (for example memberById(id: ID!): Member @lookup), and @is maps an argument to a key field. Key requirements become @require on arguments, and @internal hides lookup plumbing. @key, @shareable, @provides, @external, @override(from:) and @inaccessible carry over from Apollo, and the draft's @override has no label. The practical consequence is that entity lookups become normal, typed, individually traceable fields instead of one opaque union endpoint. Treat the spec as a direction of travel, not something to build on today.
The model covers what each subgraph owns and what it declares. What the router actually does with those declarations for the home page, how many _entities calls, in what order and whether member 42 is fetched once, is covered in the query planner part.
The Invariants
- Guarantees: Every field in the API schema has at least one declared owner and a plannable path from every operation that can select it (satisfiability). A non-
@shareablefield has exactly one resolving subgraph. Composition rejects conflicting types before any router sees them._entitiesreturns results in representation order, so cross-subgraph joins need no central code. - Does not guarantee: That
@shareableor@providescopies agree with the owner. That a batched_entitiescall is batched inside the subgraph (that needs DataLoader). That progressive override is sticky per user. That a supergraph which composes is semantically correct. That@requiresis free (it adds a sequential hop). Or that the vendor spec you build on today is the one the GraphQL Foundation eventually standardizes.