NestJS Graphql subscription -- how to disconnect client?

99 views Asked by At

I've been looking like mad trying to find some API documentation on how to do this.

I'm using 9x versions of nestjs with graphql-ws 5.11.2 and graphql-redis-subscriptions 2.5.0 and 16.5.0 graphql.

I'm doing the code first approach which has this resolve hook in the decorator where the context can be accessed.

Decorator example:

@Subscription(() => SyncEvent, {
    resolve: (value: SyncEvent, args: any, context: any, info: any) => {...})}
public async syncEvents(): Promise<AsyncIterator<SyncEvent>> {
    return this.pubSubService.pubSub.asyncIterator(session.deviceId);
  }

pubSub being defined as an object of this class:

RedisPubSub coming from graphql-redis-subscriptions node module.

There are no indicated types for context/info, info has the graphql schema and other static information.

Context has a req key with socket and client and other metadata. Unfortunately there doesn't seem to be any .close() or .end() or .disconnect() methods anywhere on it.

Calling req.socket.end() however will crash the server which I guess is a disconnect but for everyone involved.

My end purpose is on a certain value being received to disconnect the client from the server.

0

There are 0 answers