Skip to content

Commit bbef815

Browse files
docs(): update graphql docs to mention apollo v3
1 parent 5deb52a commit bbef815

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

content/graphql/quick-start.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ In this chapter, we assume a basic understanding of GraphQL, and focus on how to
99
Start by installing the required packages:
1010

1111
```bash
12-
$ npm i @nestjs/graphql graphql apollo-server-express@2.x.x
12+
$ npm i @nestjs/graphql graphql apollo-server-express
1313
```
14+
1415
> info **Hint** If using Fastify, instead of installing `apollo-server-express`, you should install `apollo-server-fastify`.
1516
17+
> warning **Warning** `@nestjs/graphql@^9` is compatible with **Apollo v3** (check out Apollo Server 3 [migration guide](https://www.apollographql.com/docs/apollo-server/migration/) for more details), while `@nestjs/graphql@^8` only supports **Apollo v2** (e.g., `[email protected]` package). Both versions (v9 and v8) are fully compatible with Nest v8 (`@nestjs/common@^8`, `@nestjs/core@^8`, etc.).
18+
1619
#### Overview
1720

1821
Nest offers two ways of building GraphQL applications, the **code first** and the **schema first** methods. You should choose the one that works best for you. Most of the chapters in this GraphQL section are divided into two main parts: one you should follow if you adopt **code first**, and the other to be used if you adopt **schema first**.

content/graphql/subscriptions.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ GraphQLModule.forRoot({
1414
}),
1515
```
1616

17+
> warning **Warning** The `installSubscriptionHandlers` configuration option has been removed from the latest version of Apollo server and will be soon deprecated in this package as well. By default, `installSubscriptionHandlers` will fallback to use the `subscriptions-transport-ws` ([read more](https://github.com/apollographql/subscriptions-transport-ws)) but we strongly recommend using the `graphql-ws`([read more](https://github.com/enisdenjo/graphql-ws)) library instead.
18+
19+
To switch to use the `graphql-ws` package instead, use the following configuration:
20+
21+
```typescript
22+
GraphQLModule.forRoot({
23+
subscriptions: {
24+
'graphql-ws': true
25+
},
26+
}),
27+
```
28+
29+
> info **Hint** You can also use both packages (`subscriptions-transport-ws` and `graphql-ws`) at the same time, for example, for backward compatibility.
30+
1731
#### Code first
1832

1933
To create a subscription using the code first approach, we use the `@Subscription()` decorator and the `PubSub` class from the `graphql-subscriptions` package, which provides a simple **publish/subscribe API**.
@@ -23,10 +37,10 @@ The following subscription handler takes care of **subscribing** to an event by
2337
```typescript
2438
const pubSub = new PubSub();
2539

26-
@Resolver(of => Author)
40+
@Resolver((of) => Author)
2741
export class AuthorResolver {
2842
// ...
29-
@Subscription(returns => Comment)
43+
@Subscription((returns) => Comment)
3044
commentAdded() {
3145
return pubSub.asyncIterator('commentAdded');
3246
}
@@ -255,13 +269,28 @@ We instantiated a local `PubSub` instance above. The preferred approach is to de
255269

256270
#### Customize subscriptions server
257271

258-
To customize the subscriptions server (e.g., change the listener port), use the `subscriptions` options property (read [more](https://www.apollographql.com/docs/apollo-server/v2/api/apollo-server.html#constructor-options-lt-ApolloServer-gt)).
272+
To customize the subscriptions server (e.g., change the path), use the `subscriptions` options property.
273+
274+
```typescript
275+
GraphQLModule.forRoot({
276+
installSubscriptionHandlers: true,
277+
subscriptions: {
278+
'subscriptions-transport-ws': {
279+
path: '/graphql'
280+
},
281+
}
282+
}),
283+
```
284+
285+
If you're using the `graphql-ws` package for subscriptions, replace the `subscriptions-transport-ws` key with `graphql-ws`, as follows:
259286

260287
```typescript
261288
GraphQLModule.forRoot({
262289
installSubscriptionHandlers: true,
263290
subscriptions: {
264-
keepAlive: 5000,
291+
'graphql-ws': {
292+
path: '/graphql'
293+
},
265294
}
266295
}),
267296
```

src/app/homepage/pages/microservices/custom-transport/custom-transport.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ <h4 appAnchor id="message-serialization"><span>Message serialization</span></h4>
197197
<p>If you need to add some custom logic around the serialization of responses on the client side, you can use a custom class that extends the <code>ClientProxy</code> class or one of its child classes. For modifying successful requests you can override the <code>serializeResponse</code> method, and for modifying any errors that go through this client you can override the <code>serializeError</code> method. To make use of this custom class, you can pass the class itself to the <code>ClientsModule.register()</code> method using the <code>customClass</code> property. Below is an example of a custom <code>ClientProxy</code> that serializes each error into an <code>RpcException</code>.</p>
198198

199199
<span class="filename">
200-
{{ 'error-handling.proxy' | extension: app0de82fc4a8bf2d269aeca1e7e184438efcf3e0d8.isJsActive }}
201-
<app-tabs #app0de82fc4a8bf2d269aeca1e7e184438efcf3e0d8></app-tabs>
200+
{{ 'error-handling.proxy' | extension: appb508b379ce892494d97bbf7fb3f5093638c8e0a8.isJsActive }}
201+
<app-tabs #appb508b379ce892494d97bbf7fb3f5093638c8e0a8></app-tabs>
202202
</span><pre><code class="language-typescript">
203203
import &#123; ClientTcp, RpcException &#125; from &#39;@nestjs/microservices&#39;;
204204

@@ -210,8 +210,8 @@ <h4 appAnchor id="message-serialization"><span>Message serialization</span></h4>
210210
</code></pre><p>and then use it in the <code>ClientsModule</code> like so:</p>
211211

212212
<span class="filename">
213-
{{ 'app.module' | extension: app2750dd81614c4ebfea443f3fdb1c35cf2c1bdc85.isJsActive }}
214-
<app-tabs #app2750dd81614c4ebfea443f3fdb1c35cf2c1bdc85></app-tabs>
213+
{{ 'app.module' | extension: app9edf2a86ee25caf1a636ec7b85e62ffa504bc949.isJsActive }}
214+
<app-tabs #app9edf2a86ee25caf1a636ec7b85e62ffa504bc949></app-tabs>
215215
</span><pre><code class="language-typescript">
216216
@Module(&#123;
217217
imports: [

0 commit comments

Comments
 (0)