Skip to content

Commit

Permalink
增加ref-query标签支持,自动为关联集合属性增加分页查询参数
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Aug 4, 2024
1 parent 6806eb6 commit cecebf6
Show file tree
Hide file tree
Showing 20 changed files with 566 additions and 22 deletions.
23 changes: 23 additions & 0 deletions docs/dev-guide/graphql/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,26 @@ query($filter1:Map, $filter2:Map){
```

后台GraphQLWebService接收到`_subArgs.`为前缀的参数之后会把它们转换为针对子属性的函数参数,并识别`filter_`前缀,将特殊前缀的变量收集在一起,转换为FilterBean对象。


## 在Excel模型中为关联属性设置`ref-query`标签
如果在`to-one`关联上设置了`ref-query`标签,则生成父表到子表的一对多集合属性时,会增加`query`标签。在`meta-gen.xlib`中,对于具有query标签的一对多属性,
会自动增加`graphql:findMethod="findList"`配置,从而为该属性增加分页查询的支持。

```xml
<prop name="children" graphql:findMethod="findList">

</prop>
```

在前台可以传入filter过滤条件和offset/limit分页参数

```
MyEntity__get(id:3) {
children(filter: {...}, limit:10){
name, status
}
}
```

在meta的prop节点上,可以配置`graphql:maxFetchSize`从而自动限制获取条数为maxFetchSize。如果不指定,则受到全局的maxPageSize的限制。
1 change: 1 addition & 0 deletions docs/dev-guide/model/excel-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Nop平台内置的表名都具有前缀`nop_`。
* `ref-updatable`:主表提交的时候允许同时更新子表数据
* `ref-grid`:自动生成界面时在主表编辑页面上增加子表表格,子表数据和主表数据一起提交
* `ref-connection`: 父表上增加类似relay框架的对子表进行分页查询的Connection属性。具体功能参见[connection.md](../graphql/connection.md)
* `ref-query`: 父表引用子表的关联集合属性设置`graphql:findMethod="findList"`,从而支持支持对子表进行分页查询。如果不传入limit参数,也不配置fetchSize,在缺省只获取maxPageSize数据。

`ref-xx`表示的是在父表中对应子表的属性上所增加的标签。例如在子表的关联上增加`ref-pub`标签,对应于在`parent.children`这个属性上增加了`pub`标签。

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
selection: id,displayName,resources{ id}
data:
id: test
_subArgs.resources.filter_status: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RESOURCE_ID,SITE_ID,DISPLAY_NAME,ORDER_NO,RESOURCE_TYPE,PARENT_ID,ICON,ROUTE_PATH,URL,COMPONENT,TARGET,HIDDEN,KEEP_ALIVE,PERMISSIONS,NO_AUTH,DEPENDS,IS_LEAF,STATUS,AUTH_CASCADE_UP,Meta_CONFIG,PROPS_CONFIG,DEL_FLAG,VERSION,CREATED_BY,CREATE_TIME,UPDATED_BY,UPDATE_TIME,REMARK
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SITE_ID,DISPLAY_NAME,ORDER_NO,URL,STATUS,EXT_CONFIG,CONFIG_VERSION,VERSION,CREATED_BY,CREATE_TIME,UPDATED_BY,UPDATE_TIME,REMARK
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data": {
"id": "test",
"displayName": "Test",
"resources": [
{
"id": "test1"
}
]
},
"status": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_chgType,RESOURCE_ID,SITE_ID,DISPLAY_NAME,ORDER_NO,RESOURCE_TYPE,PARENT_ID,ICON,ROUTE_PATH,URL,COMPONENT,TARGET,HIDDEN,KEEP_ALIVE,PERMISSIONS,NO_AUTH,DEPENDS,IS_LEAF,STATUS,AUTH_CASCADE_UP,Meta_CONFIG,PROPS_CONFIG,DEL_FLAG,VERSION,CREATED_BY,CREATE_TIME,UPDATED_BY,UPDATE_TIME,REMARK
A,test1,test,RES1,2,TOPM,,,,,,,0,0,,0,,0,1,0,,,0,0,autotest-ref,*,autotest-ref,*,
A,test2,test2,RES2,3,TOPM,,,,,,,0,0,,0,,0,1,0,,,0,0,autotest-ref,*,autotest-ref,*,
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_chgType,SITE_ID,DISPLAY_NAME,ORDER_NO,URL,STATUS,EXT_CONFIG,CONFIG_VERSION,VERSION,CREATED_BY,CREATE_TIME,UPDATED_BY,UPDATE_TIME,REMARK
A,test,Test,2,,0,,,0,autotest-ref,*,autotest-ref,*,
A,test2,Test2,3,,0,,,0,autotest-ref,*,autotest-ref,*,
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,18 @@ public void testTransFilter() {
prepareData();
run("request.yaml", "response.yaml");
}

@EnableSnapshot
@Test
public void testFindList() {
prepareData();

ApiRequest<Map<String, Object>> request = request("request.yaml", Map.class);
GraphQLArgsHelper.normalizeSubArgs(request.getSelection(), request.getData());

IGraphQLExecutionContext context = graphQLEngine.newRpcContext(null, "NopAuthSite__get", request);
ApiResponse<?> result = graphQLEngine.executeRpc(context);

output("response.yaml", result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

<prop name="createTime" allowFilterOp="eq,in,ge"/>

<!-- 设置了queryMethod,因为本身就是关联属性,所以不需要设置filter -->
<prop name="resources" displayName="资源列表" graphql:queryMethod="findList">
<graphql:orderBy>
<field name="orderNo" desc="false"/>
</graphql:orderBy>
</prop>

<prop name="resourcesList" displayName="资源列表" graphql:queryMethod="findList">
<schema bizObjName="NopAuthResource"/>

Expand Down
5 changes: 5 additions & 0 deletions nop-demo/nop-quarkus-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
<artifactId>nop-log-java</artifactId>
</dependency>

<dependency>
<groupId>io.github.entropy-cloud</groupId>
<artifactId>nop-dbtool-core</artifactId>
</dependency>

<dependency>
<groupId>io.github.entropy-cloud</groupId>
<artifactId>nop-auth-service</artifactId>
Expand Down
Loading

0 comments on commit cecebf6

Please sign in to comment.