The router and the supergraph

Intermediate · 8 min

The router is the endpoint clients call. It loads the supergraph, plans each query across subgraphs, fetches in parallel or sequence, and merges results.

Before thisApollo Federation basics

Apollo GraphQL · 8 min

The router and the supergraph

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Apollo GraphQLReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • The supergraph schema is the composed description of all subgraphs, including which subgraph owns each field and where to reach it.
  • The router receives client queries, builds a query plan from the supergraph, calls subgraphs, and merges the responses.
  • Independent fields can be fetched from subgraphs in parallel, while an entity's extra fields need a prior fetch to learn its key.
  • The router is also the place for cross-cutting policy: authentication, limits, persisted queries, telemetry and caching.
  • Composition runs outside the router, in CI or a registry, and the router receives the finished supergraph rather than composing it.

What sits in front

With subgraphs composed, clients still need one address. That address is the router. A client sends it an ordinary GraphQL query, as in the HTTP lesson, and never learns that three services answered. To clients, the router is the GraphQL server.

Apollo’s router is a standalone binary, written in Rust, that you run next to your subgraphs. It is configured with two things: a supergraph schema and a config file for policy.

The supergraph schema

The supergraph schema is the output of composition, which the previous lesson ran. I composed two subgraphs with rover supergraph compose and the result was the full client-facing schema, annotated with @join__type and @join__field directives and a join__Graph enum listing each subgraph’s name and routing URL. The annotations are the routing table. Product.name belongs to PRODUCTS, Product.reviews to REVIEWS.

Composition is a build step. You run it in CI or in a registry and hand the file to the router. The router does not compose at runtime in the managed setups; it loads or receives the finished artifact and can reload it when a new one arrives. That separation is what makes schema checks possible: you compose a proposed change before it reaches anything live.

The query plan

When a query arrives the router makes a query plan: which subgraph to call for which fields, in what order, with which representations. You can reproduce the essential steps by hand, because every subgraph speaks plain GraphQL. Take:

{ products { name reviews { body } } }

Using two @apollo/subgraph schemas, I ran what a router would:

  1. Ask products for { products { id name } }. It returned two products. The router asks for id too, even though the client did not, because it needs the key.
  2. Send reviews one _entities call with both representations, [{__typename:"Product", id:"1"}, {__typename:"Product", id:"2"}], and the selection ... on Product { reviews { body } }. It returned both lists in one response.
  3. Merge the two into the shape the client asked for.

Two fetches, in sequence, because step 2 needs step 1’s ids. Batching is why step 2 was one call for two products and not two calls. Fields that need no key from each other, say products and users side by side, can go to different subgraphs in parallel. Plan length is the main source of federation latency: each sequential hop adds a round trip, so a schema that forces five hops for a common page is a design problem to fix, not a router setting.

I did not run the router binary itself in this session, so this is a hand-built reproduction of the plan, and everything below is documentation-derived.

Policy belongs here

Because the router sees every client request, it is the natural home for cross-cutting concerns, many of which this course has already treated one service at a time:

  • Authentication at the edge, passing verified claims to subgraphs. Subgraphs still enforce authorization, since they own the data.
  • Limits: depth and cost, rate limiting, and persisted queries work best before a request fans out.
  • Telemetry: one place to emit traces for the whole plan, covered in observability and tracing.
  • Caching: query plans and, with configuration, responses.
  • Subscriptions and @defer, with their own router support and caveats.

Subgraph URLs should be reachable only from the router. If clients can call a subgraph directly, they bypass everything above.

Running one

The router is configured with a supergraph file and a YAML config, along these lines:

router --supergraph supergraph.graphql --config router.yaml

and a typical config sets the listen address, CORS, header propagation, limits and telemetry exporters. The router also has a license model: it is free to run under the Elastic License for core features, with some enterprise features gated behind a GraphOS plan. Treat those details as docs, not as something verified here, and check Apollo’s current documentation for flags and licensing, because both have changed across versions. During development, rover dev composes local subgraphs and runs a router for you.

Apollo is not the only option. Other routers and gateways implement federation, and some teams choose non-Apollo tools for performance or licensing reasons. The federation spec, not the router, is the contract.

What the video covers

“Apollo Router: the nginx for your GraphQL” is an eight-minute video from April 2026, the most recent in this course’s pool. It is on Apollo’s own channel and had few views when I checked, and I could not read a transcript or chapter list, so I cannot say which router features it demonstrates beyond what its title suggests: positioning the router as a front door for GraphQL traffic. Use it as an orientation and check what it shows against the current docs. The runner-up is a 63-minute 2022 Stripe Dev Chat session on the supergraph, long and older.

Where this fits

Now that the architecture is clear, the next lesson goes back to a single service and the practice that keeps all of this trustworthy: testing a GraphQL API.

Check yourself

  1. 01What is the supergraph schema, and who produces it?

    The composed schema of every subgraph with ownership and routing annotations, produced by composition (for example rover supergraph compose) and loaded by the router.

  2. 02Why does a query like products and their reviews need two fetches?

    The reviews subgraph needs each product's key to look it up, so the router first asks products for the ids and then sends them to reviews as entity representations.

  3. 03Why enforce depth limits and authentication in the router instead of each subgraph?

    It is one place that sees the whole client query, so the policy applies uniformly and a rejected request never reaches any subgraph.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark