QLoo graphql engine 学习一 基本试用(docker&&docker-compose)

说明:使用docker-compose 进行安装

代码框架

使用命令行工具创建

qlooctl install docker qloo-docker

运行qloo&&gloo

  • 启动
cd ./qloo-docker
docker-compose up
  • 效果

配置glooctl &&qlooctl工具

  • 下载
https://github.com/solo-io/qloo/releases
https://github.com/solo-io/gloo/releases
  • 配置环境变量

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") }}'

使用playground 查看接口

http://localhost:9090


参考资料

https://github.com/solo-io/qloo/blob/master/docs/getting_started/docker/1.md
https://qloo.solo.io/

posted on   荣锋亮  阅读(584)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2016-08-01 centos7通过yum安装mysql,并授权远程连接
2016-08-01 查看mysql主从配置的状态及修正 slave不启动问题

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示