Skip to content

What is the difference between onOperation and onSubscribe hooks ? #161

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

You must be logged in to vote

You might be mixing "subscribe" with GraphQL subscriptions, but that is not the case. The client "subscribes" for events on the server, onSubscribe is the first to be called. It allows you to manipulate the the execution arguments and skip the built-in validation and exec args construction. With it you can use dynamic schemas, implement persisted queries, skip validation, apply custom auth or introduce completely custom subscription behaviour (check the recipes out). Check it out here:

graphql-ws/src/server.ts

Lines 619 to 654 in f24e9ba

let execArgs: ExecutionArgs;
const maybeExecArgsOrErrors = await onSubscribe?.(ctx, message);
if (maybeExecArgsOrErrors) {
if (a…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@enisdenjo
Comment options

@97amarnathk
Comment options

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