Closed arunoda closed 7 years ago
@arunoda, right now you may do it in such way:
app.use('/graphql', expressGraphql((req) => ({
schema,
graphiql: false
context: {
user: req.user,
db: appInfo.db
}
})));
Thanks @nodkz. That's pretty cool. I totally miss this part in the README: https://github.com/graphql/express-graphql#providing-extensions
Where is the context object used? And how? Trying to understand a use case.
context is object , can allow context with a function
If we don't set a context, express-graphql set the http request object as the context. If we provide a context explicitly, there's no way we could access the HTTP
request
object inside aresolve
function.So, here's my suggestion. We could pass a function for the
context
. It's a mapper and it receives the request object as the first argument.See:
May be this is a breaking change if someone already passing a function for
context
. If so, we could do this with a different field likecontextMapper
.