Skip to content

How to know serverside a subscription was cancelled #1382

Answered by n1ru4l
pbackx asked this question in Q&A
Discussion options

You must be logged in to vote

Here is an example of tearing down an example after the client disconnected. https://codesandbox.io/s/regression-subscription-not-closed-d8d5mj?file=/index.ts

import { createServer, Repeater } from "@graphql-yoga/node";

const server = createServer({
  schema: {
    typeDefs: /* GraphQL */ `
      type Query {
        hello: String
      }

      type Subscription {
        currentDate: String
      }
    `,
    resolvers: {
      Query: {
        hello: () => "Hello from Yoga!"
      },
      Subscription: {
        currentDate: {
          resolve: (value) => value,
          subscribe: () =>
            new Repeater(async (next, stop) => {
              console.log("Subscription starts");

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@pbackx
Comment options

@n1ru4l
Comment options

n1ru4l Jul 18, 2022
Collaborator

@pbackx
Comment options

@deslee
Comment options

Answer selected by pbackx
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