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/quick-start.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,13 @@ In this chapter, we assume a basic understanding of GraphQL, and focus on how to
9
9
Start by installing the required packages:
10
10
11
11
```bash
12
-
$ npm i @nestjs/graphql graphql apollo-server-express@2.x.x
12
+
$ npm i @nestjs/graphql graphql apollo-server-express
13
13
```
14
+
14
15
> info **Hint** If using Fastify, instead of installing `apollo-server-express`, you should install `apollo-server-fastify`.
15
16
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
+
16
19
#### Overview
17
20
18
21
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**.
Copy file name to clipboardExpand all lines: content/graphql/subscriptions.md
+33-4Lines changed: 33 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,20 @@ GraphQLModule.forRoot({
14
14
}),
15
15
```
16
16
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
+
17
31
#### Code first
18
32
19
33
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
23
37
```typescript
24
38
const pubSub =newPubSub();
25
39
26
-
@Resolver(of=>Author)
40
+
@Resolver((of)=>Author)
27
41
exportclassAuthorResolver {
28
42
// ...
29
-
@Subscription(returns=>Comment)
43
+
@Subscription((returns)=>Comment)
30
44
commentAdded() {
31
45
returnpubSub.asyncIterator('commentAdded');
32
46
}
@@ -255,13 +269,28 @@ We instantiated a local `PubSub` instance above. The preferred approach is to de
255
269
256
270
#### Customize subscriptions server
257
271
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:
<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>
0 commit comments