Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic SSE example with Bun not streaming properly #2523

Open
Tracked by #2700 ...
babsonmatt opened this issue Mar 2, 2023 · 1 comment
Open
Tracked by #2700 ...

Basic SSE example with Bun not streaming properly #2523

babsonmatt opened this issue Mar 2, 2023 · 1 comment

Comments

@babsonmatt
Copy link

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}`
  )}`
);
@n1ru4l
Copy link
Collaborator

n1ru4l commented Mar 9, 2023

This was referenced May 7, 2024
This was referenced May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants