zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    Windows Mobile下创建cmwap接入点
    我的云之旅hadoop单机设置(2)
    ssh登录
    我的云之旅前言(1)
    实时搜索将是下一个核心
    cassandra索引目录
    图书大甩卖(操作系统、C语言、Linux) 已成交
    ehcache实例
    google推出语音搜索
    百姓网看起来还行
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/9403322.html
Copyright © 2011-2022 走看看