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

Most upvoted comments

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 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 passing ctx. For now, this small change should work, though:

Router.post('/graphql', (ctx, next) => apolloKoa(() => {...})(ctx, next));

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 of ctx.request as the only argument.