API / Apollo Gateway Interview questions
How does the @requires directive work?
@requires lets a subgraph declare that computing one of its own fields depends on a field it doesn't own, coming from that entity's owning subgraph.
type Product @key(fields: "id") { id: ID! weight: Float! @external estimatedShippingCost: Float! @requires(fields: "weight") }
Here the Shipping subgraph needs weight (owned by Products) before it can resolve estimatedShippingCost. The query planner sees this dependency at composition time and builds a plan that fetches weight from Products first, then passes it to Shipping's resolver as part of the entity representation when calling _entities.
This keeps each subgraph's data ownership clean — Shipping never has to duplicate or re-fetch product weight logic itself, it just declares the dependency and lets the planner sequence the calls correctly.
More Related questions...