Skip to content

wubaiqing/GraphQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}

学习链接

About

Type-GraphQL 演讲内容,以及效果演示 Demo。

Resources

License

Stars

Watchers

Forks

Packages

No packages published