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

Errors in Bun: The Request.url getter can only be used on instances of Request #3446

Open
whekin opened this issue Oct 14, 2024 · 3 comments

Comments

@whekin
Copy link

whekin commented Oct 14, 2024

Describe the bug

Most likely it's an issue with Bun. It happens when integrating GraphQL Yoga with Express and using express.json() middleware. Also the bug occurs when integrating Yoga with Fastify

Your Example Website or App

https://codesandbox.io/p/devbox/bun-yoga-crckwv

Steps to Reproduce the Bug or Issue

import { createYoga } from 'graphql-yoga'
import express from 'express';
 
import { createSchema } from 'graphql-yoga'
 
export const schema = createSchema({
  typeDefs: `
    type Query {
      hello: String
    }
  `,
  resolvers: {
    Query: {
      hello: () => 'world'
    }
  }
})

const app = express()
 
// The Request.url getter can only be used on instances of Request
app.use(express.json({ limit: '1mb' }));

const yoga = createYoga({ schema })

app.use(yoga.graphqlEndpoint, yoga)

app.listen(4000, () => {
  console.log('Running a GraphQL API server at http://localhost:4000/graphql')
})

Call stack:

Unexpected response: "TypeError: The Request.url getter can only be used on instances of Request
    at get (:1:11)
    at onRequest (node_modules/graphql-yoga/esm/plugins/use-health-check.js:4:17)
    at iterate (node_modules/@whatwg-node/server/esm/utils.js:380:25)
    at handleRequest (node_modules/@whatwg-node/server/esm/createServerAdapter.js:51:46)
    at requestListener (node_modules/@whatwg-node/server/esm/createServerAdapter.js:127:25)
    at <anonymous> (native)
    at handle (node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (node_modules/express/lib/router/index.js:328:13)
    at <anonymous> (node_modules/express/lib/router/index.js:286:9)
    at next (node_modules/express/lib/router/index.js:280:10)
    at <anonymous> (node_modules/body-parser/lib/read.js:137:5)
    at runInAsyncScope (node:async_hooks:159:18)
    at invokeCallback (node_modules/raw-body/index.js:238:16)
    at done (node_modules/raw-body/index.js:227:7)
    at onEnd (node_modules/raw-body/index.js:287:7)
    at emit (node:events:183:48)
    at endReadableNT (node:stream:2392:27)
    at processTicksAndRejections (:7:39)

Expected behavior

No error occurs

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Bun 1.1.30
  • @graphql-yoga/* version(s): 5.7.0

Additional context

No response

@whekin
Copy link
Author

whekin commented Oct 14, 2024

I also opened the issue in Bun's repo: oven-sh/bun#12368

@ardatan
Copy link
Collaborator

ardatan commented Dec 10, 2024

It seems to be fixed with the latest Bun;
oven-sh/bun#12368 (comment)

@ardatan ardatan closed this as completed Dec 10, 2024
@whekin
Copy link
Author

whekin commented Dec 10, 2024

@ardatan I just tried again with bun 1.1.38, same issue (both with fastify and express when using body parser)

@ardatan ardatan reopened this Dec 10, 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