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: content/graphql/federation.md
+36-48Lines changed: 36 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,15 +15,15 @@ In the next example, we'll set up a demo application with a gateway and two fede
15
15
16
16
#### Federated example: Users
17
17
18
-
First install the optional dependency for federation:
18
+
First, install the optional dependency for federation:
19
19
20
20
```bash
21
21
$ npm install --save @apollo/federation
22
22
```
23
23
24
-
#####Schema first
24
+
#### Schema first
25
25
26
-
The User service has a simple schema. Note the `@key` directive: it tells the Apollo query planner that a particular instance of User can be fetched if you have its `id`. Also note that we extend the `Query` type.
26
+
The User service has a simple schema. Note the `@key` directive: it tells the Apollo query planner that a particular instance of User can be fetched if you have its `id`. Also, note that we extend the `Query` type.
Our resolver has one extra method: `resolveReference`. It's called by the Apollo Gateway whenever a related resource requires a `User` instance. We'll see an example of this in the Posts service later on. Please note the `@ResolveReference` decorator.
97
+
Our resolver has one extra method: `resolveReference()`. It's called by the Apollo Gateway whenever a related resource requires a `User` instance. We'll see an example of this in the Posts service later on. Please note the `@ResolveReference()` decorator.
Our Post service serves aggregated posts via a `getPosts` query, but also extends our `User` type with `user.posts`
146
142
147
-
#####Schema first
143
+
#### Schema first
148
144
149
145
The Posts service references the User type in its schema by marking it with the `extend` keyword. It also adds one property to the User type. Note the `@key` directive used for matching instances of User, and the `@external` directive indicating that the `id` field is managed elsewhere.
And finally tie it together in a module. Note the schema build options, where we specify that `User` is an outside type.
298
+
And finally, tie it together in a module. Note the schema build options, where we specify that `User` is an outside type.
311
299
312
300
```ts
313
301
import { Module } from'@nestjs/common';
@@ -333,7 +321,7 @@ export class AppModule {}
333
321
334
322
#### Federated example: Gateway
335
323
336
-
First install the optional dependency for the gateway: `npm install --save @apollo/gateway`.
324
+
First, install the optional dependency for the gateway: `npm install --save @apollo/gateway`.
337
325
338
326
Our gateway only needs a list of endpoints and will auto-discover the schemas from there. Therefore it is the same for code and schema first, and the code for our gateway is very short:
339
327
@@ -387,7 +375,7 @@ class AuthenticatedDataSource extends RemoteGraphQLDataSource {
0 commit comments