graphql-community / koa-graphql

Create a GraphQL HTTP server with Koa.
MIT License
843 stars 61 forks source link

Koa 2.x #21

Closed chentsulin closed 8 years ago

chentsulin commented 9 years ago

Will need to support async await with koa 2.0:

app.use(async (ctx, next) => {
  // ...
  await next();
  // ...
});
ghost commented 8 years ago

hi @chentsulin :) when could i use koa-graphql on koa2. please i builded app based on koa2. THX.

chentsulin commented 8 years ago

For Koa 2, use koa-convert to convert the middleware:

var koa = require('koa');
var mount = require('koa-mount'); // koa-mount@2.x
var convert = require('koa-convert');
var graphqlHTTP = require('koa-graphql');

var app = new Koa();

app.use(mount('/graphql', convert(graphqlHTTP({ schema: MyGraphQLSchema, graphiql: true }))));
sibelius commented 7 years ago

@chentsulin I think it is worth to refactor this middleware to use async await, as async await landed on node 7, and the syntax is much better than generators

why do we have req and request ? - https://github.com/chentsulin/koa-graphql/blob/master/src/index.js#L100

I have a trouble with optics because of this: https://github.com/apollographql/optics-agent-js/issues/88

chentsulin commented 7 years ago

Sure, we definitely need migrate from generator to async await. I will work on this in the next few days.

request in koa is an abstraction on top of node's vanilla request object, providing additional functionality and it can avoid some buggy node behavior. But I reuse the getGraphQLParams function which exported by express-graphql and it only supports req (node's vanilla request object or decorated by express) so just a workaround there. Ideally we should use request everywhere.