When to use @shareable vs @key (Entity)?

I don’t understand the difference between defining an Entity using the @key directive and using the @shareable directive. When would I use one instead of the other?

Hello :wave:

By default in Federation subgraphs, a single object field can’t be defined or resolved by more than one subgraph schema. While both @shareable/@key directives are used to indicate the reusable/referenceable types, only entities will have corresponding reference resolver (i.e. a query that resolves the type).

Entities are entry points to your supergraph which allows you to not only reference them across supergraph but also extend their functionality (i.e. add new fields). This allows the router to create a query plan where it can execute _entities query across number of subgraphs to resolve all the entity fields from the corresponding subgraph.

Entities are automatically shareable but opposite is not true. Shareable means that the type is shared across subgraphs and can be resolved locally by various subgraphs. Shareable can also be applied on fields as opposed to the object types.

See sharing types and entities docs for additional details.