Skip to content

Commit 3f0e19d

Browse files
Merge pull request #2309 from jeremybarbet/docs/graphql-context
docs(graphql): context not in subscription object
2 parents 4d00dda + c32bb58 commit 3f0e19d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

content/graphql/subscriptions.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,22 @@ All subscriptions made with this connection will have the same `authToken`, and
334334
If you're using the `graphql-ws` package, the signature of the `onConnect` callback will be slightly different:
335335

336336
```typescript
337-
subscriptions: {
338-
'graphql-ws': {
339-
onConnect: (context: Context<any>) => {
340-
const { connectionParams, extra } = context;
341-
// user validation will remain the same as in the example above
342-
// when using with graphql-ws, additional context value should be stored in the extra field
343-
extra.user = { user: {} };
337+
GraphQLModule.forRoot<ApolloDriverConfig>({
338+
driver: ApolloDriver,
339+
subscriptions: {
340+
'graphql-ws': {
341+
onConnect: (context: Context<any>) => {
342+
const { connectionParams, extra } = context;
343+
// user validation will remain the same as in the example above
344+
// when using with graphql-ws, additional context value should be stored in the extra field
345+
extra.user = { user: {} };
346+
},
344347
},
345348
},
346349
context: ({ extra }) => {
347350
// you can now access your additional context value through the extra field
348-
}
349-
},
351+
},
352+
});
350353
```
351354

352355
#### Enable subscriptions with Mercurius driver

0 commit comments

Comments
 (0)