apollo-server: "this" context or request data is unavailable from apolloKoa()
Currently I cannot see the request data from:
Router.post('/graphql', apolloKoa(() => {...}));
It doesn’t seem possible to get the request headers from apolloKoa().
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (7 by maintainers)
Commits related to this issue
- chore(deps): update dependency @types/node-fetch to v2.3.6 (#144) — committed to apollographql/apollo-server by renovate[bot] 5 years ago
- chore(deps): update dependency @types/node-fetch to v2.3.6 (#144) — committed to apollographql/apollo-server by renovate[bot] 5 years ago
I’m currently orchestrating like this:
This gives the ‘full’ context to the third parameter in my GraphQL queries, and makes
context.state
available (or, in fact,context.*
)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.
@helfer and @saeho,
Looking forward to the change from just passing
request
to passingctx
. For now, this small change should work, though:That way you can use
ctx
however you want (e.g., pass it as GraphQL context) until this PR gets done.@mikeifomin true, although I think that’s acceptable at this point. If you could make a PR, that would be great!
@mikeifomin ok, I think we could just pass
ctx
instead ofctx.request
as the only argument.