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

graphqlExpress has no way of accepting express request through context #420

Closed
pikelnys opened this issue Jun 9, 2017 · 4 comments
Closed

Comments

@pikelnys
Copy link

pikelnys commented Jun 9, 2017

express-graphql passes the express request as a default value for context. This is very convenient when I want to do something such as check a user's authentication from the request header.

However, it does not appear that there is a way to get a handle on the express request object from inside a resolver when using graphql-server-express. Is there a specific reason you left this out? Am I missing some other way to get a handle on the req?

Thanks.

@helfer
Copy link
Contributor

helfer commented Jun 9, 2017

@pikelnys if you want, you can pass the request object into the context that every resolver gets. you can do this in the function that returns the configuration. Something like this (copied from here) will do:

graphqlExpress(request => ({
  schema: typeDefinitionArray,
  context: { user: request.session.user }
}))

@yvele
Copy link

yvele commented Jun 8, 2018

@helfer Thank you! But this should be documented 😅

PS: #757

@Muphet
Copy link

Muphet commented Oct 19, 2018

@helfer wait how?
app.use('/api', bodyParser.json(), jwt({ secret: process.env.JWT_SECRET, credentialsRequired: false, }), graphqlExpress(request => ({ schema, context: { authUser: request.user } })));
returns typeerror: graphqlExpress is not a function

i can't figure that out

@dewhurstwill
Copy link

@Muphet when your importing graphqlExpress you need to do
const { graphqlHTTP } = require("express-graphql");
then use graphqlHTTP in place of graphqlExpress

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants