API / Apollo Gateway Interview questions
What is the purpose of the _service and _entities fields in a federated subgraph schema?
Both are automatically added to every subgraph's schema by a federation library like @apollo/subgraph — you don't hand-write either one.
_service { sdl }– lets the gateway fetch a subgraph's raw, federation-annotated schema string during composition, without the subgraph needing a separate introspection endpoint just for this._entities(representations: [_Any!]!): [_Entity]!– is what the gateway calls at request time to resolve entity references, passing a batch of key-field representations and getting back the fields that subgraph owns for each one.
Together they cover the two moments a subgraph needs to interact with the gateway: composition time (describing its shape via _service) and request time (resolving entity data via _entities). Neither field is meant to be called directly by client applications.
More Related questions...