postgraphile 基本试用

我的测试环境使用docker 进行的安装

基本安装

./start_containers.sh
  • postgraphile(postgraphql)
npm install -g postgraphile

基本使用

  • 创建数据库
psql -U postgres -h localhost
create database appdemo
  • 启动postgraphile

    使用watch 参数可以自动更新api

postgraphile -c "postgres://postgres:postgres@localhost:5432/appdemo" --watch

参考结果

  • 使用graphql playground访问
  • 创建表
create table person (
  id serial primary key,
  name varchar not null,
  about text,
  email varchar not null unique,
  created_at timestamp default current_timestamp
);

自动更新结果

  • 数据查询操作
    ```code
    query {
    allPeople{
    nodes {
    id
    name
    }
    }
    }
<img width="699" height="458" src="7e4d60d1-f7f9-4752-8170-ef9f56a668b2_files/82548778.png">
* 添加数据
```code
mutation {
  createPerson(input:{
     clientMutationId:"demoappdemo",
     person:{
      name:"dalong",
      about:"demoappdemo",
      email:"[email protected]",
      createdAt:"2018-07-10"
     }
  }){
    person {
      name
      about
      email
    }
  }
}

与prisma比较

主要是扩展行行,prisma是多数据库支持的,基于nodejs 开发模式,同时生态不错,有好多相关的组件,使用上主要
以模型优先的模式,postgraphile 相对就简单了,只需要安装基本上不用写代码(当然角色,权限的问题,依然需要处理,
而且在ID的处理上postgraphile有点模糊,还有待仔细阅读。
详细的比较后边会有介绍

参考资料

https://www.graphile.org/postgraphile/introduction/
https://www.prisma.io/

猜你喜欢

转载自www.cnblogs.com/rongfengliang/p/9265979.html