Skip to content

Commit 18bd227

Browse files
authored
docs(graphql): graphql-ws context value example
When using subscriptions with graphql-ws package, passing additional context values are different from subscription-transport-ws package
1 parent 4c31b40 commit 18bd227

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

content/graphql/subscriptions.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,14 @@ If you're using the `graphql-ws` package, the signature of the `onConnect` callb
334334
subscriptions: {
335335
'graphql-ws': {
336336
onConnect: (context: Context<any>) => {
337-
const { connectionParams } = context;
338-
// the rest will remain the same as in the example above
337+
const { connectionParams, extra } = context;
338+
// user validation will remain the same as in the example above
339+
// when using with graphql-ws, additional context value should store into extra field
340+
extra.user = { user: {} };
339341
},
340342
},
343+
context: ({ extra }) => {
344+
// you then can access your additional context value through extra field
345+
}
341346
},
342347
```

0 commit comments

Comments
 (0)