一、克隆项目、安装依赖、启动 GraphQL 服务
git clone https://github.com/wubaiqing/GraphQL.git && \
cd GraphQL && \
yarn install && \
yarn start
二、访问本地服务
http://localhost:4000/graphql
三、执行查询门店列表案例
query {
shops {
canteenId
canteenName
canteenAddress
}
}
四、执行查询门店列表和门店详情案例
query {
shop(index: 0) {
canteenName
}
shops {
canteenId
canteenName
canteenAddress
}
}
五、类型扩展案例
query {
shop(index: 0) {
device {
equId
equName
}
}
shops {
device {
equId
equName
}
}
}
type DeviceType {
canteenId: Int!
equId: Int!
equName: String!
createTime: String
}
type Mutation {
createShop(canteenName: String!, canteenAddress: String!): ShopType!
}
type Query {
shop(index: Float!): ShopType!
shops(offset: Float = 0): [ShopType!]!
countShop: Int!
}
type ShopType {
canteenId: Int!
canteenName: String!
canteenAddress: String!
createTime: String!
device: DeviceType
}