Skip to content

How to use dataloaders with graphql-ws subscriptions? #198

Answered by n1ru4l
97amarnathk asked this question in Q&A
Discussion options

You must be logged in to vote

You can provide a custom subscribe function as an option.

graphql-ws/src/server.ts

Lines 162 to 170 in 784ea15

/**
* Is the `subscribe` function from GraphQL which is
* used to execute the subscription operation.
*
* Throwing an error from within this function will
* close the socket with the `Error` message
* in the close event reason.
*/
subscribe?: (args: ExecutionArgs) => OperationResult;

Right now execute function is an implementation detail of subscribe and thus there is no option to replace it. However, writing your own is pretty straight-forward: https://github.com/dotansimha/envelop/pull/183/files#diff-8172edfaa44ae…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by 97amarnathk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants