hasura graphql-engine v1.0.0-alpha26 版本新功能试用

hasura graphql-engine v1.0.0-alpha26 已经发布了,有好多新的变动,测试使用docker 环境,同时pg 数据库使用了citus

citus 是一个方便扩展的pg 数据库扩展解决方案,很不错。

环境准备

docker-compose && citus

  • docker-compose 文件
version: '2.1'

services:
  graphql-engine:
    image: hasura/graphql-engine:v1.0.0-alpha26
    ports:
    - "8080:8080"
    command: >
      /bin/sh -c "
      graphql-engine --database-url postgres://postgres@master/postgres serve --enable-console;
      "
  master:
    container_name: "${COMPOSE_PROJECT_NAME:-citus}_master"
    image: 'citusdata/citus:7.5.1'
    ports: ["${MASTER_EXTERNAL_PORT:-5432}:5432"]
    labels: ['com.citusdata.role=Master']
  worker:
    image: 'citusdata/citus:7.5.1'
    labels: ['com.citusdata.role=Worker']
    depends_on: { manager: { condition: service_healthy } }
  manager:
    container_name: "${COMPOSE_PROJECT_NAME:-citus}_manager"
    image: 'citusdata/membership-manager:0.2.0'
    volumes: ['/var/run/docker.sock:/var/run/docker.sock']
    depends_on: { master: { condition: service_healthy } }
  • 启动
docker-compose up -d

  • 测试数据表
-- DDL generated by Postico 1.4.2
-- Not all database features are supported. Do not use for backup.

-- Table Definition ----------------------------------------------

CREATE TABLE citus.userlogin (
    id integer DEFAULT nextval('citus.userlogin_id_seq'::regclass) PRIMARY KEY,
    username text NOT NULL,
    userage integer NOT NULL
);

-- Indices -------------------------------------------------------

CREATE UNIQUE INDEX userlogin_pkey ON citus.userlogin(id int4_ops);

-- DDL generated by Postico 1.4.2
-- Not all database features are supported. Do not use for backup.

-- Table Definition ----------------------------------------------

CREATE TABLE citus.platformuser (
    id integer DEFAULT nextval('citus.platformuser_id_seq'::regclass) PRIMARY KEY,
    platformtype text NOT NULL,
    loginuser integer NOT NULL DEFAULT nextval('citus.platformuser_loginuser_seq'::regclass),
    platformname text NOT NULL
);

-- Indices -------------------------------------------------------

CREATE UNIQUE INDEX platformuser_pkey ON citus.platformuser(id int4_ops);

新功能测试

  • order_by 查询
query {
   citus_userlogin(order_by:{id:asc}) {
    id
    username
    userage
  }
}
  • 聚合参数操作
query {
   citus_userlogin_aggregate {
     aggregate {
       max {
        userage
      }
    }
  }
}


  • 关系聚合


  • event trigger

说明

测试只是一部分,实际上还有预设值的,都比较简单,hasura graphql-engine 是越来越方便了,hasura 团队很给力,
对于开发来说太方便了

参考资料

https://docs.hasura.io/1.0/graphql/manual/getting-started/index.html
https://github.com/hasura/graphql-engine/releases
https://www.citusdata.com/

posted on 2018-10-27 16:22  荣锋亮  阅读(405)  评论(0编辑  收藏  举报

导航