#graphql subscription -- how to disconnect subscriber?

13 messages · Page 1 of 1 (latest)

hexed spear
#

I'm using the code-first approach with subscriptions + redis pubsub, been trying to find some docs on how to disconnect the user if there's a certain event published for that channel.

This is how my code looks currently:

@Subscription(() => SyncEvent, {
    resolve: (value: SyncEvent) => {
....

public async syncEvents(
    @CurrentSession() session: IAccessToken
  ): Promise<AsyncIterator<SyncEvent>> {
    // checking if a device is attached to the session so we can throw if not
    if (!session.deviceId) {
      throw new IntentionalException(ExceptionEnum.Events['000'], 'NOT_FOUND');
    }
    // returning the async interator
    return this.pubSubService.pubSub.asyncIterator(session.deviceId);
  }

Using this bit:

graphql-redis-subscriptions

Where pubSub comes from @Inject('PUB_SUB') public readonly pubSub: RedisPubSub, RedisPubSub coming from that package above

#

but really the bit is what/how can I inject the subscription connection?

#

what types do I use to disconnect the socket?

hexed spear
#

I can see I have access to some sort of context here with req.socket defined but no close/disconnect methods:

resolve: (value: SyncEvent, args: any, context: any, info: any) => {
#

there seem to be some functions on the event but I don't think they're actionable by the looks of it

#

on ctx.req.client._events

#

context.req.client.end() kinda works but sometimes crashes the server

#

Altair still shows the connection as ongoing

#

ah no, it doesn't work

#

const gqlContext = GqlExecutionContext.create(context); this doesn't work, neither the ArgumentHost one

#

These are they keys on the context object:

'_readableState', '_events',
'_eventsCount', '_maxListeners',
'socket', 'httpVersionMajor',
'httpVersionMinor', 'httpVersion',
'complete', 'rawHeaders',
'rawTrailers', 'joinDuplicateHeaders',
'aborted', 'upgrade',
'url', 'method',
'statusCode', 'statusMessage',
'client', '_consuming',
'_dumped', 'parser',
'headers', 'log',
'session'

Then on the req.socket:

[
'connecting',
'_hadError',
'_parent',
'_host',
'_closeAfterHandlingError',
'_readableState',
'_events',
'_eventsCount',
'_maxListeners',
'_writableState',
'allowHalfOpen',
'_sockname',
'_pendingData',
'_pendingEncoding',
'server',
'_server',
'parser',
'on',
'addListener',
'prependListener',
'setEncoding',
'_paused',
'timeout'
]

then on req.client:

[
'connecting',
'_hadError',
'_parent',
'_host',
'_closeAfterHandlingError',
'_readableState',
'_events',
'_eventsCount',
'_maxListeners',
'_writableState',
'allowHalfOpen',
'_sockname',
'_pendingData',
'_pendingEncoding',
'server',
'_server',
'parser',
'on',
'addListener',
'prependListener',
'setEncoding',
'_paused',
'timeout'
]

surreal atlas