[ALPHA][NODE.JS] BUG: Gutted / Useless Request Object in Context Factory
See original GitHub issueWhen 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:
- Created 2 years ago
- Comments:9
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ardatan is v2 =
graphql-yoga@alpha
? If so, then it is the same problem I faced with alpha, but, this old versiongraphql-yoga
fixed the issue.It is
Request
object created bycross-undici-fetch
. It has the API of https://developer.mozilla.org/en-US/docs/Web/API/Requestrequest.headers.get('content-type')
would returnapplication/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.