官方例子用的是 express,使用的是 rootValue 这个参数,在 koa 里也可以使用:
// schema
const rootComment = {
comment: () => {
return [
{
id: 1,
avatar: 'https://static001.geekbang.org/account/avatar/00/19/19/a0/84f95280.jpg',
name: 'Junting',
isTop: true,
content: '你最帅了~',
publishDate: '今天',
commentNum: 10,
praiseNum: 5
}
]
}
}
// http
app.use(
graphqlHTTP({
schema,
rootValue: rootComment,
graphiql: true
})
);
展开