Skip to content

How to detect a subscription has already been initialised? #379

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

You must be logged in to vote

I don't quite understand what you're trying to achieve, so I'll just literally answer your requirement:

...detect if async iterator has been returned for a specific combination of query /input parameters...

Here's an example of how you may achieve that (untested code ahead):

import { ExecutionArgs } from 'graphql';
import { OperationResult } from 'graphql-ws';
import { useServer } from 'graphql-ws/lib/use/ws';
import { WebSocketServer } from 'ws';

function onCompleteNotifier(args: ExecutionArgs, operation: OperationResult) {
  // distribute event however you see fit
}

// map of IDs to GraphQL operations (with original execution arguments)
const idToOp: Record<
  string,
  { args: Exec…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by enisdenjo
Comment options

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

@RichardWright
Comment options

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