Skip to content

Subscription Context #207

Answered by enisdenjo
lucapinelli asked this question in Q&A
Jun 21, 2021 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Yap, you can use the context server option (there is also a "ws server usage with custom context value" recipe). You can either provide it with a static context or a function which returns a context.

This value is then used as the GraphQL execution arguments contextValue:

graphql-ws/src/server.ts

Lines 718 to 723 in 79bd429

// if `onSubscribe` didn't specify a context, inject one
if (!('contextValue' in execArgs))
execArgs.contextValue =
typeof context === 'function'
? await context(ctx, message, execArgs)
: context;

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@lucapinelli
Comment options

@bnussman
Comment options

@enisdenjo
Comment options

@bnussman
Comment options

Answer selected by lucapinelli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants