Here is the example Build GraphQL Server with Express

The only difference from that example is the way plugining middleware.

In server.js of Koa:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import * as Koa from 'koa'
import * as GraphqlHTTP from 'koa-graphql'
import * as Router from 'koa-router'
import Schema from './schema'

const PORT = 3457

const app = new Koa()
const router = new Router()
router.all('/graphql', GraphqlHTTP({
schema: Schema,
pretty: true,
graphiql: true,
}))

app.use(router.routes()).use(router.allowedMethods())

app.listen(PORT, () => {
console.log('server is running at: ' + PORT)
})