@@ -5,18 +5,18 @@ Graphql模板运行时工具,自动生成标准模板和Typescript类型,
5
5
[ ![ GitHub Workflow Status (branch)] ( https://img.shields.io/github/workflow/status/redux-model/graphql/CI/master )] ( https://github.com/redux-model/graphql/actions )
6
6
[ ![ Codecov] ( https://img.shields.io/codecov/c/github/redux-model/graphql )] ( https://codecov.io/gh/redux-model/graphql )
7
7
8
+ # 特性
9
+ * 只需写一次,Graphql语法和Typescript同时拥有
10
+ * 自动收集参数
11
+ * 自动识别参数基础类型
12
+ * 单一职责,只生成标准graphql字符串
13
+ * 支持所有graphql语法
8
14
9
15
# 安装
10
16
``` bash
11
17
yarn add @redux-model/graphql
12
18
```
13
19
14
- # 注意事项
15
- 因为action本来就定义了参数,所以函数参数不再做类型约束。函数参数需遵循:` xxx_Int ` , ` yyy_String! ` , ` zzz_ObjInput ` ,以下划线` _ ` 分割参数名和类型,这么做的好处是:
16
-
17
- 1 . 能够自动收集参数到模板顶部,提高效率
18
- 2 . 传递实参时,对类型一目了然,防止出错
19
-
20
20
# 基础用法
21
21
``` typescript
22
22
import { Model } from ' @redux-model/react' ;
@@ -76,18 +76,18 @@ class TestModel extends Model<Data> {
76
76
const tpl = graphql .query ({
77
77
getUser: {
78
78
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 ({
80
80
id: types .number ,
81
81
title: types .string ,
82
82
})),
83
83
}
84
84
});
85
85
86
86
// 生成模板:
87
- // query GetUser ($page: Int, $size: Int) {
87
+ // query GetUser ($page: Int! , $size: Int) {
88
88
// getUser: {
89
89
// id
90
- // logs (page: $page, size : $size) {
90
+ // logs (page: $page, pageSize : $size) {
91
91
// id
92
92
// title
93
93
// }
@@ -106,8 +106,8 @@ class TestModel extends Model<Data> {
106
106
return this
107
107
.post <Response >(' /graphql' )
108
108
.graphql (tpl ({
109
- page_Int: page ,
110
- size_Int: size ,
109
+ page ,
110
+ size ,
111
111
}))
112
112
.onSuccess ((state , action ) => {
113
113
return action .response .data ;
@@ -242,8 +242,8 @@ if ('age' in getUser) {
242
242
``` typescript
243
243
const tpl = graphql .query ({
244
244
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
247
247
id: types .number ,
248
248
title: types .string ,
249
249
}),
0 commit comments