Skip to content

Commit 986a95b

Browse files
shorgiMeschreiber
andauthored
docs: entities intro (#3206)
Update Intro to Entities --------- Co-authored-by: Maria Elisabeth Schreiber <[email protected]>
1 parent a8c3fd2 commit 986a95b

File tree

1 file changed

+24
-13
lines changed
  • docs/source/schema-design/federated-schemas/entities

1 file changed

+24
-13
lines changed

docs/source/schema-design/federated-schemas/entities/intro.mdx

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
---
22
title: Introduction to Entities
3-
subtitle: Resolve federated types across multiple subgraphs
4-
description: Learn to define, contribute to, and reference object types that resolve their fields across multiple subgraphs in a federated GraphQL architecture.
3+
subtitle: Fundamental keyed object type of Apollo Federation
4+
description: Learn to define, contribute to, and reference entities, the fundamental object types of Apollo Federation that resolve their fields across one or more subgraphs.
55
redirectFrom:
66
- /federation/entities
77
---
88

9-
Federated schemas let multiple subgraphs collaboratively define and resolve fields for shared object types.
10-
This guide shows you how to define a shared object type called an _entity_.
9+
<Note>
10+
11+
Before getting started with entities, you may want to check out the [Introduction to Apollo Federation](/graphos/schema-design/federated-schemas/federation) for a conceptual overview.
1112

12-
Before you get started, you may want to check out the [Introduction to Apollo Federation](/graphos/schema-design/federated-schemas/federation) for a conceptual overview.
13+
</Note>
1314

1415
## Entity overview
1516

16-
_Entities_ are a fundamental aspect of federated schemas.
17-
In a supergraph, an entity is an object type that can resolve its fields across multiple subgraphs.
18-
Each subgraph can contribute different fields to the entity and is responsible for resolving only the fields that it contributes.
19-
This enables subgraphs to adhere to the separation of concerns principle.
17+
In Apollo Federation, federated data objects are represented as _entities_. Entities are objects that can be fetched with one or more unique key fields. Like a row in a database table, an entity contains fields of various types, and it can be uniquely identified by a key field or set of fields.
2018

21-
For example, this `Product` entity's fields are defined and resolved across two subgraphs:
19+
Entities are defined in subgraph schemas. Each subgraph can contribute different fields to an entity it defines and is responsible for _resolving_ it—returning only the fields that it contributes. This enables subgraphs to adhere to the separation of concerns principle.
20+
21+
An _entity type_ is an object type that has been [defined as an entity](#defining-an-entity). Because an entity is keyed, an entity type's definition must have a `@key` directive. For example, this `Product` entity's fields are defined and resolved across two subgraphs:
2222

2323
<CodeColumns>
2424

@@ -45,7 +45,7 @@ Only object types can be entities.
4545

4646
</Note>
4747

48-
This guide goes over how to define entities in your subgraph schemas and code.
48+
The rest of this guide goes over how to define entities in your subgraph schemas and code.
4949

5050
## Defining an entity
5151

@@ -54,6 +54,14 @@ To define an entity within a particular subgraph, you do the following:
5454
1. Apply the [`@key` directive](#1-define-a-key) to an object type.
5555
2. Define the object type's [reference resolver](#2-define-a-reference-resolver).
5656

57+
<Tip>
58+
59+
With Apollo Connectors, you add [connector directives](/graphos/schema-design/connectors/directives) instead of writing reference resolver code.
60+
61+
You can [set `entity: true`](/graphos/schema-design/connectors/directives#rules-for-entity-true) for the `@connect` directive to provide an entity resolver for its fields.
62+
63+
</Tip>
64+
5765
<ExpansionPanel title="Watch the video overview">
5866

5967
<Wistia WistiaId="7geep7jxo6" />
@@ -117,12 +125,15 @@ Though not strictly required, it's best to use non-nullable fields for keys. If
117125

118126
### 2. Define a reference resolver
119127

120-
The `@key` directive effectively tells the router, "This subgraph can resolve an instance of this entity if you provide its unique key." For this to be true, the subgraph must define a _reference resolver_ for the entity.
128+
The `@key` directive effectively tells the router, "This subgraph can resolve an instance of this entity if you provide its unique key." For this to be true, the subgraph must have a _reference resolver_ for the entity.
121129

122130
<Note>
123131

124132
This section describes how to create reference resolvers in Apollo Server.
125-
If you're using another [subgraph-compatible library](/graphos/reference/federation/compatible-subgraphs), see its documentation for creating reference resolvers or the equivalent functionality.
133+
134+
- If you're using Apollo Connectors, the [connectors directives](/graphos/schema-design/connectors/directives) declare which REST endpoints to use to resolve entity fields, so you don't write any reference resolvers.
135+
136+
- If you're using another [subgraph-compatible library](/graphos/reference/federation/compatible-subgraphs), see its documentation for creating reference resolvers or the equivalent functionality.
126137

127138
</Note>
128139

0 commit comments

Comments
 (0)