How do you implement entity resolution in Apollo Federation?
Answer
Entity resolution is how Federation resolves entities (types with @key) across subgraph boundaries. The process: (1) Service A returns a stub reference: { __typename: "User", id: "42" }. (2) The Router sends these stubs to Service B's _entities query: query(_representations: [{ __typename: "User", id: "42" }]) { _entities { ... on User { orders { id } } } }. (3) Service B's __resolveReference function fetches the full entity: User: { __resolveReference: (ref) => db.user.findById(ref.id) }. Complex keys: @key(fields: "region { name }") — nested key fields. Multiple keys: a type can have multiple @key directives. Stubbed entities: Service B doesn't need to implement all User fields — only those it extends. The Router's query planner optimizes entity fetching with batching.
Previous
What is Apollo Federation v2 and how does the supergraph work?
Next
What are the security vulnerabilities specific to GraphQL?
More GraphQL Questions
View all →- Advanced What is Apollo Federation v2 and how does the supergraph work?
- Advanced What are the security vulnerabilities specific to GraphQL?
- Advanced How does the GraphQL query planning and execution pipeline work?
- Advanced What is the @defer and @stream directive and how do they work?
- Advanced How do you design a scalable GraphQL schema?