API / Apollo Gateway Interview questions
How does the @provides directive work?
@provides is the mirror image of @requires. It lets a subgraph declare that, when it resolves a field returning an entity, it can also directly supply certain fields of that entity itself — letting the query planner skip an otherwise-necessary extra round trip to the owning subgraph.
type Review { product: Product! @provides(fields: "name") } type Product @key(fields: "id") { id: ID! name: String! @external }
If the Reviews subgraph's own database already stores a denormalized copy of the product name alongside each review, it can advertise that with @provides(fields: "name"). When a client asks for a review's product name, the planner can take it straight from the Reviews subgraph response instead of issuing a separate call to Products.
It's purely an optimization — the same data would still be reachable without @provides, just with one more network hop.
More Related questions...