You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/source/schema-design/federated-schemas/entities/intro.mdx
+24-13
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
---
2
2
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.
5
5
redirectFrom:
6
6
- /federation/entities
7
7
---
8
8
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.
11
12
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>
13
14
14
15
## Entity overview
15
16
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.
20
18
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:
22
22
23
23
<CodeColumns>
24
24
@@ -45,7 +45,7 @@ Only object types can be entities.
@@ -54,6 +54,14 @@ To define an entity within a particular subgraph, you do the following:
54
54
1. Applythe [`@key` directive](#1-define-a-key) to an object type.
55
55
2. Define the object type's [reference resolver](#2-define-a-reference-resolver).
56
56
57
+
<Tip>
58
+
59
+
With Apollo Connectors, you add [connector directives](/graphos/schema-design/connectors/directives) insteadofwritingreferenceresolvercode.
60
+
61
+
Youcan [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
+
57
65
<ExpansionPanel title="Watch the video overview">
58
66
59
67
<Wistia WistiaId="7geep7jxo6" />
@@ -117,12 +125,15 @@ Though not strictly required, it's best to use non-nullable fields for keys. If
117
125
118
126
### 2. Define a reference resolver
119
127
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.
121
129
122
130
<Note>
123
131
124
132
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), seeitsdocumentationforcreatingreferenceresolversortheequivalentfunctionality.
133
+
134
+
- If you're using Apollo Connectors, the [connectors directives](/graphos/schema-design/connectors/directives) declarewhichRESTendpointstousetoresolveentityfields, soyoudon'twriteanyreferenceresolvers.
0 commit comments