• 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/

  • 相关阅读:
    js异步编程思想【node的精华】
    python偏函数
    软工划水日报-安卓端侧部署(1) 4/23
    软工划水日报-模型预测 4/22
    软工划水日报-《构建之法》阅读笔记SONO.5 4/21
    软工划水日报-paddle模型训练(3) 4/20
    软工划水日报-paddle模型训练(2) 4/19
    软工划水日报-paddle模型训练(1) 4/18
    软工划水日报-CUDA下载与安装 4/17
    软工划水日报-AIchallager数据集下载及处理 4/16
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/9403322.html
Copyright © 2020-2023  润新知