目录
初识Hasura和周边
Hasura |
graphQL规范的一种实现,作为graphQL服务器。 |
GraphQL |
GraphQL | A query language for your API GraphQL 是一种API规范,是一个基于类型系统来执行查询的服务端运行时。GraphQL 并没有和任何特定数据库或者存储引擎绑定,而是依靠你现有的代码和数据支撑。 个人理解:图查询语言 用于检索数据的api查询语言 类比restful规范,用于定义接口;理解为是一种规范,如sql,结构性查询语言,与具体数据库无关。 类型系统:由自定义的各种数据模型构成,包括对象类型、标量、枚举、列表、接口、输入类型等。 最佳实践:通过单入口提供http服务的完整功能,返回json形式。 |
postgresql |
对象关系型数据库 docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=chl_postgre -d postgres su postgres createdb mydb |
举例:hasura自动生成的graphQL API
url |
http://host:port/v1/graphql |
method |
post |
header |
Content-Type = application/json; charset=utf-8 |
body |
查询举例: {"query":"query queryAuthor {chl_t_author {id age desc name}}"} |
编辑举例: {"query":"mutation MyMutation {insert_chl_t_mv(objects: {author_id: 1, desc: \"mv描述\", name: \"mv14\"}) {returning {id}}}"} |
数据模型-维护 |
|
数据模型-外键关系 |
|
数据模型-角色访问控制 |
|
grapqlAPI-查询数据 |
|
grapqlAPI-编辑数据 |
|
action业务逻辑01-配置graphql和模型 |
|
action业务逻辑02-访问的rest接口url |
|
action业务逻辑03-request参数转换 |
|
action业务逻辑04-response转换 |