Closed chentsulin closed 8 years ago
hi @chentsulin :) when could i use koa-graphql on koa2. please i builded app based on koa2. THX.
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 }))));
@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
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.
Will need to support async await with koa 2.0: