Federation & Composition
Many service schemas composed into one client-facing graph under Apollo Federation — a specification of its own, not part of GraphQL's. Interviewers raise it wherever GraphQL meets microservices.
part ofGraphQLoverview, primer and where to startread it →on this pageshowhide
explore
- One Graph, Many Services4 questions
- Subgraph Schemas & Entity Keys4 questions
- Entity Resolution4 questions
- Field Ownership Directives4 questions
- Query Planning5 questions
- Composition Conflicts4 questions
- Stitching Versus Composition4 questions
- Cross-Service Fetch Amplification3 questions
- Authorization Across Subgraphs4 questions
- Subgraph Failure & Partial Data4 questions
- Supergraph & Client Schemas3 questions
questions
page 2 of 2Which federation schema do you diff for client-breaking changes before a subgraph deploys?
basics
~20 sDiff the API schema, because that is the only document consumers see. A subgraph SDL diff misses changes the other subgraphs decide, and a supergraph diff is full of routing churn that never reaches a client.
How do you decide whether a company runs one GraphQL graph or several?
basics
~20 sDecide on audience and traversal, not tidiness. One graph earns its cost only where real client operations cross domains. Separate graphs are right when audiences, cadences or trust boundaries differ, or nobody can staff the platform a shared graph needs.
How do you decide which subgraph should own a field so that query plans stay shallow?
basics
~20 sStart from the hot operations, not the schema. Place a field where the traffic that matters reaches it in the fewest dependent hops, and treat ownership as a team decision with a real migration cost.
When would you keep a working stitched GraphQL gateway instead of moving to composition?
basics
~20 sKeep it when the mapping is edited rarely by the people who own the services, when some merged schemas are not yours to change, or when you rely on gateway transforms composition cannot express. Move when it becomes a cross-team queue.
Where should authorization live in a federated graph — the router, each subgraph, or the services behind them?
basics
~20 sSplit it by what each layer can know. A router has the credential, the document and the schema but no data, so it can only enforce coarse rules. Per-record rules must live in the subgraph or below.
In a federated graph with many services, which subgraph failures should be allowed to fail a whole request?
basics
~20 sOnly the ones whose absence would make the rest of the response wrong or unsafe to act on. Everything else degrades to a hole. Tier the subgraphs by that test, then encode each tier in nullability, budgets and the client contract.
Why are federation's _entities and _service named with one underscore rather than two?
basics
~20 sThe GraphQL specification reserves the double-underscore prefix for the introspection system and forbids schema authors from using it. Federation is a layer built on ordinary GraphQL, so its added members take a single underscore instead — legal, and conventionally set aside for machinery.
In a Federation 1 subgraph schema, what does the extend keyword on a type mean?
basics
~20 sThe extend keyword marks the type as owned by another subgraph: this schema only contributes extra fields to a type it did not define, so composition treats the two declarations as one type rather than a clash.
In Apollo Federation, how does composition merge an enum that two subgraphs define with different values?
basics
~20 sIt depends where the enum is used. Federation 2 takes the union for an enum used only in output positions, the intersection for one used only in input positions, and exact agreement when it is used both ways.
When a federation router builds one _entities call, why does it deduplicate representations?
basics
~20 sBecause a list usually names the same entity many times: 143 artworks by 37 artists yield 37 distinct keys. Sending each key once cuts payload and subgraph work. It is a router optimization, not a rule the federation specification imposes.
Why does a federation router add fields to a subgraph fetch that nobody selected?
basics
~20 sBecause the next step has to be addressable. Into each fetch the router injects __typename and the key fields of any object whose remaining fields another subgraph owns, then strips those values back out before serialising the response.
How does a stitched GraphQL gateway resolve a field whose data lives in another service?
basics
~20 sThe gateway becomes a client of that service. It resolves the parent first, then builds a brand-new document against the second service using values from that parent as arguments, and grafts the result into the response tree.
When would a subgraph declare @key(fields: "id", resolvable: false) on a type?
basics
~20 sWhen the subgraph only points at the entity and cannot look one up. It declares the identity so its own fields can reference the object, while telling composition never to route key lookups for that type here.
showing 31–43 of 43