honojs / node-server

Node.js Server for Hono
https://hono.dev
348 stars 43 forks source link

ReadableStream issue @hono/node-server <> GraphQL Yoga #77

Open maoosi opened 1 year ago

maoosi commented 1 year ago

Issue

Since updating to @hono/node-server@1.0.0, I'm having an issue using GraphQL Yoga. The server immediately crashes with the below message:

TypeError: The "readableStream" argument must be an instance of ReadableStream. Received an instance of bound PonyfillReadableStream
    at new NodeError (node:internal/errors:399:5)
    at Object.newStreamReadableFromReadableStream (node:internal/webstreams/adapters:482:11)
    at Function.Readable.fromWeb (node:internal/streams/readable:1403:27)
    at Server.<anonymous> (file:///workspace/node_modules/@hono/node-server/dist/listener.mjs:49:35)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'ERR_INVALID_ARG_TYPE'

Reproduction

I have created a minimal reproduction on https://codesandbox.io/p/sandbox/optimistic-lichterman-tvsgh8

Workaround

Rolling back to @hono/node-server@0.6.0 fixes the issue.

yusukebe commented 1 year ago

Hi @maoosi

This is a workaround:

export default createYoga({
  fetchAPI: { fetch, Request, ReadableStream, Response }, // <--- Add Node.js native APIs
  graphqlEndpoint: '/',
  schema: createSchema({
    typeDefs: /* GraphQL */ `
      type Query {
        hello: String
      }
    `,
    resolvers: {
      Query: {
        hello: () => 'world'
      }
    }
  })
})
maoosi commented 1 year ago

Thanks @yusukebe, your suggested workaround is working good on my end!

cayter commented 10 months ago

Facing the same issue with normal static assets serving. I tried removing Readable.fromWeb() here and it worked. Is this the only place we need to update?