Skip to content

Basic SSE example with Bun not streaming properly #2523

@babsonmatt

Description

@babsonmatt

Describe the bug

Using the provided, basic example of using graphql-yoga with Bun + graphiql to create a "countdown" subscription, the data data doesnt return until the subscription has ended (as opposed to a streaming countdown you just get the final result)

Your Example Website or App

Please see attached code (couldn't find an online playground for bun)

Steps to Reproduce the Bug or Issue

  1. Go to http://0.0.0.0:3000/graphql?query=subscription+%7B%0A++countdown%28from%3A+3%29%0A%7D
  2. Click the "Execute Query" button
  3. Wait for result

Expected behavior

Expected to see streaming results, but I'm only seeing results upon completion.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Bun: 0.5.8
  • @graphql-yoga/* version(s): 3.7.0

Additional context

import { createYoga, createSchema } from 'graphql-yoga';
const yoga = createYoga({
  schema: createSchema({
    typeDefs: /* GraphQL */ `
      type Query {
        greetings: String
      }

      type Subscription {
        countdown(from: Int!): Int!
      }
    `,
    resolvers: {
      Query: {
        greetings: () => 'Hello from Yoga in a Bun app!',
      },
      Subscription: {
        countdown: {
          // This will return the value on every 1 sec until it reaches 0
          subscribe: async function* (_, { from }) {
            for (let i = from; i >= 0; i--) {
              await new Promise((resolve) => setTimeout(resolve, 1000));
              yield { countdown: i };
            }
          },
        },
      },
    },
  }),
});
const server = Bun.serve(yoga);
console.info(
  `Server is running on ${new URL(
    yoga.graphqlEndpoint,
    `http://${server.hostname}:${server.port}`
  )}`
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions