PART 1 · VISUAL CONCEPT 03

Federation v2 Entities & Directives

How do independent subgraphs stitch one Product object together without ever calling each other directly?

Interactive Lab 01 · Query._entities Wire Visualizer

Step Through Cross-Subgraph Entity Stitching

Basic @key · Step 4 / 4
Subgraph Calls 3 Calls Products + Inv + Reviews
Network Hops 2 Waves 1 Root + 1 Parallel Fan-Out
Serial Depth 2 Serial Inv & Reviews run in parallel
Representations Sent 2 Objects { __typename, sku }
Step 4: Router merges fields from all subgraphs into one unified JSON response. PARALLEL FAN-OUT
1. Client Query & SDL Supergraph
2. Query._entities Wire Payload @key fields
3. Merged Response Attribution Stitched
Interactive Lab 02 · Federation v2 Composition Rules

Toggle Directives & Watch Composition Validate Live

VALID SUPERGRAPH
1. @shareable on Product.name ON

Both Products and Inventory define Product.name. Without @shareable, composition rejects duplicate ownership.

2. @requires + @external VALID (+1 Hop)

shippingCost needs weightKg from Products. Missing @external breaks satisfiability.

3. @key(..., resolvable: false) OFF

Marks Inventory as a stub reference owner—returns { __typename, sku } without implementing __resolveReference.

VALID SUPERGRAPH — Both subgraphs compose cleanly into one unified graph.
Plan impact: +1 serial hop when shippingCost is queried
Products Subgraph SDL Owner
Inventory Subgraph SDL Extension
Mental Model · 26 Lines of Pure TypeScript

__resolveReference.ts — How Inventory Hydrates a Product

__resolveReference.ts

      

Subgraphs Never Call Subgraphs

Products, Inventory, and Reviews stay 100% decoupled. Only the Apollo Router orchestrates joins via Query._entities and merges the final JSON.

@key Is a Join Contract

A @key(fields: "sku") directive tells the Router the exact primary key tuple needed to look up an entity in another subgraph—just like a distributed foreign key.

@requires Adds a Hop, @provides Saves One

@requires forces a serial dependency fetch before calling the target subgraph, while @provides inlines a shared field to skip an entire subgraph roundtrip.