Q35: How do Federation Entities and `@key` directives work?

Difficulty:AdvancedTopic:Federation

In Apollo Federation, an Entity is a type that can extend across subgraphs. The @key directive defines its primary key.

Subgraphs can resolve parts of an entity by referencing its key via an __resolveReference resolver function.

Federated Subgraph Schema
type User @key(fields: "id") {
  id: ID!
  username: String
}

The @key directive designates id as the cross-service entity lookup key.

Key Takeaways
  • @key converts standard object types into federated Entities capable of cross-subgraph extension.

Knowledge Check

Which special resolver function must a subgraph implement to fetch entity fields for federated joins?