QLoo graphql engine 学习一 基本试用(docker&&docker-compose)
说明:使用docker-compose 进行安装
代码框架
使用命令行工具创建
qlooctl install docker qloo-docker
运行qloo&&gloo
- 启动
cd ./qloo-docker docker-compose up
- 效果
配置glooctl &&qlooctl工具
- 下载
- 配置环境变量
mac
cat ~/.bash_profile export PATH=$PATH:/Users/dalong/Downloads/qloo
基本demo
- 启动demo 服务
docker run -d -p 1234:8080 soloio/petstore-example:latest
创建petstore 的gloo upstream
使用使用命令行工具,或者直接编写文件,注意qloo-docker_default 或者根据目录命名修改
- 使用glooctl
cat << EOF | glooctl upstream create -f - name: petstore type: static spec: hosts: # gateway ip for the docker network - addr: $(docker inspect qloo-docker_default -f '{{ (index .IPAM.Config 0).Gateway }}') port: 1234 EOF
- 使用配置文件
cat > ./_gloo_config/upstreams/petstore.yaml << EOF name: petstore type: static spec: hosts: # gateway ip for the docker network - addr: $(docker inspect qloo-docker_default -f '{{ (index .IPAM.Config 0).Gateway }}') port: 1234 EOF
查看petsore 函数
glooctl upstream get
效果
创建graphql schema
- petstore.graphql
# The query type, represents all of the entry points into our object graph type Query { pets: [Pet] pet(id: Int!): Pet } type Mutation { addPet(pet: InputPet!): Pet } type Pet{ id: ID! name: String! status: Status! } input InputPet{ id: ID! name: String! tag: String } enum Status { pending available }
- 上传schema(qlooctl 工具)
qlooctl schema create petstore -f petstore.graphql
- 查看注册的resolvermap(实际上就是graphql 的schema &&query && Mutation )
qlooctl resolvermap get petstore-resolvers -o yaml
效果
注册schema 的resolver
# register findPetById for Query.pets (specifying no arguments) qlooctl resolvermap register -u petstore -f findPetById Query pets # register a resolver for Query.pet qlooctl resolvermap register -u petstore -f findPetById Query pet # register a resolver for Mutation.addPet # the request template tells QLoo to use the Variable "pet" as an argument qlooctl resolvermap register -u petstore -f addPet Mutation addPet --request-template '{{ marshal (index .Args "pet") }}'