question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ALPHA][NODE.JS] BUG: Gutted / Useless Request Object in Context Factory

See original GitHub issue

When creating a server like so (with express):

const yoga = createServer({
  schema,
  context: req => {
    user: req.user,
    session: req.session,
    loaders: req.user ? makeLoaders(req.user) : null
  },
  maskedErrors: production ? true : false
});

app.use('/graphql', express.json(), yoga.requestListener);

The req object given has no useful available information. Despite populating the express Request object with additional data in middleware, none of it exists – in addition, it’s impossible to grab the headers/query/body properties for some reason.

This is on latest 2.0.0-alpha-13f075f.0 and 2.0.1-canary-ac3f3a9.0.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
hazemalabiadcommented, Jan 18, 2022

@ardatan is v2 = graphql-yoga@alpha ? If so, then it is the same problem I faced with alpha, but, this old version graphql-yoga fixed the issue.

1reaction
ardatancommented, Jan 11, 2022

It is Request object created by cross-undici-fetch. It has the API of https://developer.mozilla.org/en-US/docs/Web/API/Request request.headers.get('content-type') would return application/json for example. You are right about the docs 😃 We’re working on it.

We are not planning to put environment’s request object(NodeJS in this case) but export a helper function to get it; https://github.com/dotansimha/graphql-yoga/pull/796

But if request isn’t still exposed in context factory function, this seems a bug we need to solve. Would you create a PR with a failing test that shows nothing is exposed in context factory fn.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's a good way to extend Error in JavaScript?
Mosts environments set the stack property, but fileName and lineNumber are practically useless to be used in inheritance. So, the minimalistic approach is:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found