@@ -5,18 +5,18 @@ Graphql模板运行时工具,自动生成标准模板和Typescript类型,
55[ ![ GitHub Workflow Status (branch)] ( https://img.shields.io/github/workflow/status/redux-model/graphql/CI/master )] ( https://github.com/redux-model/graphql/actions )
66[ ![ Codecov] ( https://img.shields.io/codecov/c/github/redux-model/graphql )] ( https://codecov.io/gh/redux-model/graphql )
77
8+ # 特性
9+ * 只需写一次,Graphql语法和Typescript同时拥有
10+ * 自动收集参数
11+ * 自动识别参数基础类型
12+ * 单一职责,只生成标准graphql字符串
13+ * 支持所有graphql语法
814
915# 安装
1016``` bash
1117yarn add @redux-model/graphql
1218```
1319
14- # 注意事项
15- 因为action本来就定义了参数,所以函数参数不再做类型约束。函数参数需遵循:` xxx_Int ` , ` yyy_String! ` , ` zzz_ObjInput ` ,以下划线` _ ` 分割参数名和类型,这么做的好处是:
16-
17- 1 . 能够自动收集参数到模板顶部,提高效率
18- 2 . 传递实参时,对类型一目了然,防止出错
19-
2020# 基础用法
2121``` typescript
2222import { Model } from ' @redux-model/react' ;
@@ -76,18 +76,18 @@ class TestModel extends Model<Data> {
7676const tpl = graphql .query ({
7777 getUser: {
7878 id: types .number ,
79- logs: types .fn ([' page_Int ' , ' size_Int ' ], types .array ({
79+ logs: types .fn ([' page: Int! ' , ' pageSize as size: Int ' ], types .array ({
8080 id: types .number ,
8181 title: types .string ,
8282 })),
8383 }
8484});
8585
8686// 生成模板:
87- // query GetUser ($page: Int, $size: Int) {
87+ // query GetUser ($page: Int! , $size: Int) {
8888// getUser: {
8989// id
90- // logs (page: $page, size : $size) {
90+ // logs (page: $page, pageSize : $size) {
9191// id
9292// title
9393// }
@@ -106,8 +106,8 @@ class TestModel extends Model<Data> {
106106 return this
107107 .post <Response >(' /graphql' )
108108 .graphql (tpl ({
109- page_Int: page ,
110- size_Int: size ,
109+ page ,
110+ size ,
111111 }))
112112 .onSuccess ((state , action ) => {
113113 return action .response .data ;
@@ -242,8 +242,8 @@ if ('age' in getUser) {
242242``` typescript
243243const tpl = graphql .query ({
244244 getUser: {
245- id: types .number .include (' test_Boolean ' ), // number | undefined
246- logs: types .skip (' other_Boolean ' ).object ({ // object | undefined
245+ id: types .number .include (' test: Boolean ' ), // number | undefined
246+ logs: types .skip (' other: Boolean ' ).object ({ // object | undefined
247247 id: types .number ,
248248 title: types .string ,
249249 }),
0 commit comments