-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Accessing Request in Apollo Server 2 #1066
Comments
The const myServer = new ApolloServer({
schema: executableSchema,
context: async ({req}) => {
const data = await someStuff();
return {
token: data.stuff,
user: req.session.user
}
}
}); |
The context as a function is a perfect way to do this. Thanks @eugene1g for the code snippet! It would be awesome if you could open a PR to the |
@eugene1g Can context be a function that returns a Promise like you show above? I'm running Apollo Server 2.0.0-beta.3 and my resolvers are receiving an unresolved Promise in context param. My context function looks just like yours. |
@darkadept Nope! I just tested /cc @evans |
@darkadept I looked through the code and looks like there is regression in how However, there seems to be a hacky workaround for const generateContext = async ({req}) => {
const data = await someStuff();
return {
token: data.stuff,
user: req.session.user
}
}
const myServer = new ApolloServer({
schema: executableSchema,
context: params => () => generateContext(params);
}); This "works" in a sense is that it gives you async context generators in |
@eugene1g Oh wow. That works! Thanks. What's the roadmap for this context function though? Is it supposed to support async context functions in the future? I just realized this should probably be it's own issue. Should I open an issue for this? |
I expect the
|
@eugene1g Definitely a regression! I'll add a test and publish another beta |
Confirming this has been fixed |
Is there any way of accessing the request object from the underlying express app in Apollo Server 2 beta? Much like this one #420.
The text was updated successfully, but these errors were encountered: