API / Apollo Gateway Interview questions
Explain the internal working of entity resolution using _entities and reference resolvers?
When Subgraph B needs to contribute fields to an entity it doesn't own, the gateway calls a special field that Federation automatically adds to every subgraph's schema: _entities(representations: [_Any!]!): [_Entity]!.
The flow looks like this: the gateway first fetches the entity's base data (including its @key fields) from the owning subgraph. It then builds a list of "representations" — small objects containing __typename plus the key field values — and sends that list to Subgraph B's _entities field in a single call.
type Query { _entities(representations: [_Any!]!): [_Entity]! }
Inside Subgraph B, this is backed by a reference resolver — commonly written as a __resolveReference function for that type — which receives each representation and returns just the fields that subgraph owns. Because the whole batch of representations is sent in one call, Subgraph B can also batch its own underlying database lookups rather than issuing one query per entity instance.
More Related questions...