Skip to content

Latest commit

 

History

History
116 lines (103 loc) · 2.36 KB

README.md

File metadata and controls

116 lines (103 loc) · 2.36 KB

GraphQL 演讲内容

演讲 PPT 在线版

启动项目

一、克隆项目、安装依赖、启动 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
    }
  }
}

整个 Demo 类型定义

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
}

学习链接