Showcase about GraphQL server based on RESTful API server with focus on easy setup, performance and great developer experience. see this article(基于 RESTful API 的 GraphQL 服务构建) for more information.
# install dependencies
yarn
# run koa server
npm run examples:koa
# run mock restful server
npm run start:json
*Tips: project does not have hot module reload, if you have modify the code, you need to rebuild it & db.json will be reset.
Altair GraphQL Client is recommended for debugging.
mutation createUser($body: UserInput!) {
createUser(body: $body) {
name
}
}
variables:
{
"body": {
"name": "gogogo111",
"orderId": 1,
"productId": 1
}
}
query {
user(userId: 1) {
name
}
}
query {
user(userId: 1) {
name
orders {
price
user {
name
orders {
price
}
}
}
collections {
title
}
}
}
query {
products {
id
title
users(productId: 1) {
name
}
}
}
# product users will only request once, not three
GET /products 200 3.528 ms - 437
GET /products/1/users 200 4.274 ms - 84
Thank you here!
- GraphQL-BFF:微服务背景下的前后端数据交互方案
- 第一届 GraphQLParty 首场工程实践图文版
- GraphQL Tools - Schema directives
- the-power-of-graphql-directives
- GraphQL Tools - Mocking
Welcome to commit issue and pull request!