-
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
"this" context or request data is unavailable from apolloKoa() #144
Comments
Koa 2 is supported I guess. So headers contains in ctx object. And yes for now there is no way to pass the context data into options function. |
@saeho @mikeifomin What's the best way we can fix your problems? cc @HriBB |
Currently even though Apollo-Server supports Koa2, it really doesn't. In order to allow authentication with each GraphQL query, we need to be able to pass some sort of token or auth info to the POST request's header. Then I need to be able to do something with that header info or pass it into the context. Currently Koa2 implementation of Apollo-Server does not make this possible. Thus, Apollo-Server is unusable in Koa2. |
@saeho Right, so how do we make it useable? Having access to it in the options function would be enough, right? I thought that was already the case, but I might be mistaken. |
I stopped using ApolloKoa few days or a week ago but as far as I remember there was no way for me to see the header from the options function. So even though the ability to use a function to generate the options was there, I couldn't do anything with it. |
@mikeifomin ok, I think we could just pass |
@saeho I'm working on app written with the KoaJS 2. And with the easy fix everything is ok and I have more cleaner resolvers code with async/await style. |
@helfer your proposal looks better in case of "clean api". But it will break compatibility. |
@mikeifomin true, although I think that's acceptable at this point. If you could make a PR, that would be great! |
Looking forward to the change from just passing Router.post('/graphql', (ctx, next) => apolloKoa(() => {...})(ctx, next)); That way you can use |
Hey. Sorry for the late reply, I'm really busy these days. So if I understand this correctly, all that needs to be changed to resolve this issue is to pass |
@HriBB, that's correct. 😄 |
I'm currently orchestrating like this: router.post('/graphql',
(context, next) => apolloKoa({
schema,
context,
})(context, next),
); This gives the 'full' context to the third parameter in my GraphQL queries, and makes Is there anything wrong with this approach? This pattern of orchestrating middleware in Koa2 is pretty common, when that same middleware needs access to ctx.state or ctx.request. |
Im not a koa expert but it looks like a decent solution.. |
Currently I cannot see the request data from:
It doesn't seem possible to get the request headers from apolloKoa().
The text was updated successfully, but these errors were encountered: