API / Apollo Gateway Interview questions
What is the @key directive used for?
@key marks the field or fields that uniquely identify instances of an entity type, which is what lets other subgraphs reference and extend that type without owning it fully.
type Product @key(fields: "id") { id: ID! name: String! price: Float! }
Any subgraph that wants to contribute additional fields to Product re-declares the type with the same @key and implements a reference resolver that receives just the id and returns the fields it owns. A type can even declare multiple @key directives if different subgraphs need to look it up by different combinations of fields.
More Related questions...