hayes/pothos

unsubscribe function for subscriptionField

Open

#450 opened on Jul 4, 2022

View on GitHub
 (2 comments) (0 reactions) (0 assignees)TypeScript (183 forks)auto 404
documentationgood first issuehelp wanted

Repository metrics

Stars
 (2,609 stars)
PR merge metrics
 (PR metrics pending)

Description

I want to implement my own subscription manager. I can't use the plugin because I need a different API. How do I know if a subscription was ended / lost?

I need something like this:

builder.subscriptionField('station', (t) =>
  t.field({
    args: {
      where: t.arg({
        type: "StationWhereInput"
      })
    },
    type: 'StationSubscriptionPayload',
    subscribe: (_parent: any, args: any, context: any, { fieldName }: ResolveShape) => {
      const channel = uid()
      SUBSCRIPTIONS[channel] = { ...args, channelName: fieldName }
      return pubsub.subscribe(channel)
    },
    unsubscribe: ???,
    resolve: async ({ node, mutation }) => {
      return {
        mutation,
        node
      }
    }
  })
)

I need to track active Subscriptions and want to know when someone stopped a subscription. (remove it from my SUBSCRIPTIONS object).

Or if this is not possible, is there something like apollo's withFilter? That would be even cooler. https://www.apollographql.com/docs/apollo-server/data/subscriptions/#filtering-events

Contributor guide