From af6ae17439d1748ce72ed5ebba2315c4dd64c9f9 Mon Sep 17 00:00:00 2001 From: flytreeleft Date: Wed, 31 Jul 2024 10:38:39 +0800 Subject: [PATCH 1/5] =?UTF-8?q?Docs:=20=E5=86=85=E5=AE=B9=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E5=92=8C=E9=94=99=E8=AF=AF=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/dev-guide/graphql/connection.md | 28 +++++++++++++----------- docs/tutorial/simple/4-complex-query.md | 29 ++++++++++++++++--------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/docs/dev-guide/graphql/connection.md b/docs/dev-guide/graphql/connection.md index a95c30e8e..bb6964d84 100644 --- a/docs/dev-guide/graphql/connection.md +++ b/docs/dev-guide/graphql/connection.md @@ -10,18 +10,20 @@ ```xml - - - - - - - + + + + + + + + + ``` @@ -81,7 +83,7 @@ query($filter1:Map, $filter2:Map){ items{ id } - }, + } inactiveRecords: mySubObjectConnection(filter:$filter2, limit:5){ total diff --git a/docs/tutorial/simple/4-complex-query.md b/docs/tutorial/simple/4-complex-query.md index 79a196509..c62f6257f 100644 --- a/docs/tutorial/simple/4-complex-query.md +++ b/docs/tutorial/simple/4-complex-query.md @@ -134,7 +134,7 @@ Nop平台中服务函数的返回值并不会被直接序列化为JSON返回到 xmlns:graphql="graphql"> @@ -146,12 +146,12 @@ Nop平台中服务函数的返回值并不会被直接序列化为JSON返回到 ``` * 通过`graphql:connectionProp`可以指定ORM层面的关联属性,通过它可以自动推理得到`graphql:filter`配置。此时如果再配置`graphql:filter`就表示在关联查询条件的基础上再补充额外的过滤条件 -* findConnection对应于返回结果为GraphQLConnection类型。关于它的具体介绍,参见[connection.md](../../dev-guide/graphql/connection.md) +* `findConnection`对应于返回结果为GraphQLConnection类型。关于它的具体介绍,参见[connection.md](../../dev-guide/graphql/connection.md) 在REST调用模式下,我们可以通过`_subArgs.{propName}.filter_xx=yy`这种形式来传递子表过滤条件 ``` -http://localhost:8080/r/NopAuthSite__get?id=main&%40selection=id,displayName,resourcesList%7Bid%7D&_subArgs.resourcesList.filter_status=1 +http://localhost:8080/r/NopAuthSite__get?id=main&%40selection=id,displayName,resourcesList%7Bitems%7Bid,displayName%7D%7D&_subArgs.resourcesList.filter_status=1 ``` * 通过`@selection`可以传递类似GraphQL的字段映射配置,此时**特殊字符`@`和大括号等需要进行编码处理**,否则后台解析URL的时候报错,会返回400错误码。 @@ -161,10 +161,13 @@ http://localhost:8080/r/NopAuthSite__get?id=main&%40selection=id,displayName,res ```graphql query($filter:Map){ NopAuthSite_get(id:"main"){ - id, - displayName, + id + displayName resourcesList(filter:$filter,limit:10,offset:0){ - id, displayName + items{ + id + displayName + } } } } @@ -184,13 +187,19 @@ variables: ```graphql query($filter1:Map, $filter2: Map){ NopAuthSite_get(id:"main"){ - id, - displayName, + id + displayName activeResources: resourcesList(filter:$filter1,limit:10,offset:0){ - id, displayName + items{ + id + displayName + } } inactiveResources: resourcesList(filter:$filter2,limit:10,offset:0){ - id, displayName + items{ + id + displayName + } } } } From b2593144e55286c79fdf85f65398de7bf73634b0 Mon Sep 17 00:00:00 2001 From: flytreeleft Date: Wed, 31 Jul 2024 10:45:16 +0800 Subject: [PATCH 2/5] =?UTF-8?q?Nop=20GraphQL:=20=E4=BF=AE=E6=AD=A3=20OrmEn?= =?UTF-8?q?tityPropConnectionFetcher=20=E4=B8=AD=E5=AF=B9=20QueryBean#limi?= =?UTF-8?q?t=20=E7=9A=84=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E7=A1=AE=E4=BF=9D=20graphql:maxFetchSize=20=E7=9A=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=80=BC=E4=BC=98=E5=85=88=E4=BA=8E=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E5=92=8C=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE(nop.grap?= =?UTF-8?q?hql.max-page-size)=E6=8C=87=E5=AE=9A=E7=9A=84=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orm/fetcher/OrmEntityPropConnectionFetcher.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nop-graphql/nop-graphql-orm/src/main/java/io/nop/graphql/orm/fetcher/OrmEntityPropConnectionFetcher.java b/nop-graphql/nop-graphql-orm/src/main/java/io/nop/graphql/orm/fetcher/OrmEntityPropConnectionFetcher.java index 42cddb501..1984e7263 100644 --- a/nop-graphql/nop-graphql-orm/src/main/java/io/nop/graphql/orm/fetcher/OrmEntityPropConnectionFetcher.java +++ b/nop-graphql/nop-graphql-orm/src/main/java/io/nop/graphql/orm/fetcher/OrmEntityPropConnectionFetcher.java @@ -86,16 +86,17 @@ public Object get(IDataFetchingEnvironment env) { } if (queryMethod != GraphQLQueryMethod.findFirst) { - if (maxFetchSize > 0) { - if (query.getLimit() > maxFetchSize) { - query.setLimit(maxFetchSize); - } - } if (query.getLimit() <= 0) { query.setLimit(10); } else if (query.getLimit() > CFG_GRAPHQL_MAX_PAGE_SIZE.get()) { query.setLimit(CFG_GRAPHQL_MAX_PAGE_SIZE.get()); } + + if (maxFetchSize > 0) { + if (query.getLimit() > maxFetchSize) { + query.setLimit(maxFetchSize); + } + } } if (input.getFilter() != null) { From ff2d8e479721dd38b174c8e3d607e59311e4aec8 Mon Sep 17 00:00:00 2001 From: flytreeleft Date: Wed, 31 Jul 2024 10:50:52 +0800 Subject: [PATCH 3/5] =?UTF-8?q?Nop=20GraphQL:=20=E7=A1=AE=E4=BF=9D=20Query?= =?UTF-8?q?Bean#limit=20=E7=9A=84=E7=BC=BA=E7=9C=81=E5=80=BC=E6=9D=A5?= =?UTF-8?q?=E8=87=AA=E4=BA=8E=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE=20nop.gr?= =?UTF-8?q?aphql.default-page-size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java | 3 ++- .../graphql/orm/fetcher/OrmEntityPropConnectionFetcher.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java b/nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java index e7be2031c..7f6c32653 100644 --- a/nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java +++ b/nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java @@ -137,6 +137,7 @@ import static io.nop.biz.BizErrors.ERR_BIZ_OBJ_NO_DICT_TAG; import static io.nop.biz.BizErrors.ERR_BIZ_PROP_NOT_MANY_TO_MANY_REF; import static io.nop.biz.BizErrors.ERR_BIZ_TOO_MANY_LEFT_JOIN_PROPS_IN_QUERY; +import static io.nop.graphql.core.GraphQLConfigs.CFG_GRAPHQL_DEFAULT_PAGE_SIZE; import static io.nop.graphql.core.GraphQLConfigs.CFG_GRAPHQL_MAX_PAGE_SIZE; import static io.nop.orm.utils.OrmQueryHelper.resolveRef; @@ -352,7 +353,7 @@ protected QueryBean prepareFindPageQuery(@Name("query") QueryBean query, } if (query.getLimit() <= 0) { - query.setLimit(10); + query.setLimit(CFG_GRAPHQL_DEFAULT_PAGE_SIZE.get()); } if (query.getLimit() > maxPageSize) { diff --git a/nop-graphql/nop-graphql-orm/src/main/java/io/nop/graphql/orm/fetcher/OrmEntityPropConnectionFetcher.java b/nop-graphql/nop-graphql-orm/src/main/java/io/nop/graphql/orm/fetcher/OrmEntityPropConnectionFetcher.java index 1984e7263..c97125443 100644 --- a/nop-graphql/nop-graphql-orm/src/main/java/io/nop/graphql/orm/fetcher/OrmEntityPropConnectionFetcher.java +++ b/nop-graphql/nop-graphql-orm/src/main/java/io/nop/graphql/orm/fetcher/OrmEntityPropConnectionFetcher.java @@ -37,6 +37,7 @@ import java.util.function.BiConsumer; import java.util.function.Function; +import static io.nop.graphql.core.GraphQLConfigs.CFG_GRAPHQL_DEFAULT_PAGE_SIZE; import static io.nop.graphql.core.GraphQLConfigs.CFG_GRAPHQL_MAX_PAGE_SIZE; import static io.nop.orm.utils.OrmQueryHelper.resolveRef; @@ -87,7 +88,7 @@ public Object get(IDataFetchingEnvironment env) { if (queryMethod != GraphQLQueryMethod.findFirst) { if (query.getLimit() <= 0) { - query.setLimit(10); + query.setLimit(CFG_GRAPHQL_DEFAULT_PAGE_SIZE.get()); } else if (query.getLimit() > CFG_GRAPHQL_MAX_PAGE_SIZE.get()) { query.setLimit(CFG_GRAPHQL_MAX_PAGE_SIZE.get()); } From d6f717fc5c8f4f7dadfe969cadeef41e54daca3b Mon Sep 17 00:00:00 2001 From: flytreeleft Date: Wed, 31 Jul 2024 16:44:43 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Docs:=20=E8=B0=83=E6=95=B4=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E5=86=85=E5=AE=B9=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/compare/nop-vs-apijson.md | 12 ++++++----- docs/dev-guide/graphql/connection.md | 2 +- docs/dev-guide/orm/eql.md | 12 +++++------ docs/dev-guide/orm/orm.md | 6 +++--- docs/dev-guide/orm/sql-lib.md | 23 +++++++++++---------- docs/dev-guide/recipe/filter-list.md | 27 ++++++++++++++----------- docs/tutorial/simple/4-complex-query.md | 10 +++++---- 7 files changed, 50 insertions(+), 42 deletions(-) diff --git a/docs/compare/nop-vs-apijson.md b/docs/compare/nop-vs-apijson.md index 2d13ce4e1..7cfbdfd3e 100644 --- a/docs/compare/nop-vs-apijson.md +++ b/docs/compare/nop-vs-apijson.md @@ -721,7 +721,7 @@ APIJSON中 `["contactIdList<>":38710]`等价于执行SQL过滤条件`json_contai allowFilterOp="contains,eq"> - json_contains(o.contactIdList,${value}) + json_contains( o.contactIdList, ${value} ) @@ -733,7 +733,7 @@ APIJSON中 `["contactIdList<>":38710]`等价于执行SQL过滤条件`json_contai * 可以配置``来执行转换逻辑。例子中时使用`filter.xlib`标签库中的``标签函数来动态生成SQL片段。 * 如果感觉上面的配置有些繁琐,可以利用Nop平台内置的元编程机制在编译期为JSON类型的字段统一生成相应的transFilter配置。这样看起来就像是原生支持json_contains运算符。 -``` +```xml ``` @@ -766,7 +766,9 @@ APIJSON中,如下调用 - EXISTS(SELECT * FROM Comment o2 WHERE o2.momentId=${filter.getAttr('momentId')}) + EXISTS( + SELECT * FROM Comment o2 WHERE o2.momentId= ${ filter.getAttr('momentId') } + ) @@ -802,7 +804,7 @@ APIJSON中,如下调用 * 可以使用inject函数从IoC容器中获取bean,或者使用import语法导入Java类。 * 可以利用XPL模板语言的标签抽象机制类简化调用。例如 -``` +```xml @@ -911,7 +913,7 @@ Nop平台采用标准的ORM设计,一般要求先获取数据到Java内存中 对于少数需要直接在数据库中执行递增或者递减语法的情况,可以在XBiz模型中直接执行SQL语句来进行处理。 -``` +```xml diff --git a/docs/dev-guide/graphql/connection.md b/docs/dev-guide/graphql/connection.md index bb6964d84..35068d7ae 100644 --- a/docs/dev-guide/graphql/connection.md +++ b/docs/dev-guide/graphql/connection.md @@ -99,7 +99,7 @@ query($filter1:Map, $filter2:Map){ ## REST请求时通过`_subArgs`简化传参方式 -``` +```json /r/MyObject__get?id=3&@selection=activeRecords:mySubObjectConnection,inactiveRecords:mySubObjectConnection { diff --git a/docs/dev-guide/orm/eql.md b/docs/dev-guide/orm/eql.md index bbb0e2391..4ee2c6c4c 100644 --- a/docs/dev-guide/orm/eql.md +++ b/docs/dev-guide/orm/eql.md @@ -23,7 +23,7 @@ select o.dept.name, u.type from NopAuthUser o left join MyEntity u on o.id = u.userId select o.dept.name, u.type -from NopAuthUser o , MyEntity u +from NopAuthUser o , MyEntity u where o.id = u.userId ``` @@ -36,25 +36,25 @@ select o from NopAuthUser o limit 10 offset 0 ## 4. for update语句 -``` +```sql select o from NopAuthUser o where id = 1 for update ``` ## 5. 删除语句 -``` +```sql delete from NopAuthUser o wher o.id = 3 ``` ## 6. 更新语句 -``` +```sql update NopAuthUser o set o.name = 'a' where o.id = 2 ``` ## 7. 插入语句 -``` +```sql insert NopAuthUser(name, status) values('a',1) ``` @@ -76,4 +76,4 @@ insert NopAuthUser(name, status) values('a',1) * `>>` : 右移位 * % : 取余 * ^ -* +* diff --git a/docs/dev-guide/orm/orm.md b/docs/dev-guide/orm/orm.md index c3a4d50ed..a9363fdd4 100644 --- a/docs/dev-guide/orm/orm.md +++ b/docs/dev-guide/orm/orm.md @@ -2,7 +2,7 @@ NopORM是一个类似Hibernate的完整ORM引擎,因此它也是通过OrmSession来管理所有加载到内存中的实体对象。在同一个session中,只会按照id从数据库加载一次,然后得到的实体对象就会被缓存到session中。 -```javascript +```java MyEntity entity = dao.getEntityById("3"); List entities = dao.findAll(); assertTrue(entityes.contains(entity)); @@ -19,9 +19,9 @@ assertTrue(entityes.contains(entity)); * 向集合对象中加入实体隐含的就表示该实体也要同步到数据库中,因此调用parent.getChildren().add(child)之后不需要再调用dao.saveEntity(child)来保存子实体。 * 从集合对象中删除实体会自动删除该实体,除非它的owner属性值被设置为null. -``` +```java parent.getChildren().remove(child); -// child.setParent(null); +// child.setParent(null); ``` 如果不调用child.setParent(null),则从parent的children集合中删除child表示要从数据库中删除child。而如果设置了child的parent为null,则表示解除父实体和子实体的关联关系。 diff --git a/docs/dev-guide/orm/sql-lib.md b/docs/dev-guide/orm/sql-lib.md index 9ade54b34..d5a952273 100644 --- a/docs/dev-guide/orm/sql-lib.md +++ b/docs/dev-guide/orm/sql-lib.md @@ -194,13 +194,13 @@ sql模式针对SQL输出的情况做了特殊处理,主要增加了如下规 如果确实希望直接输出SQL文本,拼接到SQL语句中,可以使用raw函数来包装。 -``` +```sql from MyEntity_${raw(postfix)} o ``` 此外,NopOrm对于参数化SQL对象本身也建立了一个简单的包装模型 -``` +```java SQL = Text + Params ``` @@ -228,8 +228,9 @@ XLang语言还内置了一些调试特性,方便在元编程阶段对问题进 3. 任何表达式都可以追加调用扩展函数`$`,它会自动打印当前表达式对应的文本、行号以及表达式执行的结果, 并返回表达式的结果值。例如 -``` -x = a.f().$(prefix) 实际对应于 +```java +x = a.f().$(prefix) +// 实际对应于 x = DebugHelper.v(location,prefix, "a.f()",a.f()) ``` @@ -237,12 +238,12 @@ x = DebugHelper.v(location,prefix, "a.f()",a.f()) 利用标签库可以引入各种自定义的扩展逻辑。比如根据不同的数据库方言生成不同的SQL语句。 -``` +```xml select ... - from my_entity +from my_entity ``` ## 8. Mapper接口 @@ -327,8 +328,8 @@ OrmSessionFactory支持IEntityFilterProvider配置,nop-auth-service模块提 也可以使用在构造SQL对象时直接指定enableFilter属性 -```javascript - SQL sql = SQL.begin().enableFilter(true).sql("...").end(); +```java +SQL sql = SQL.begin().enableFilter(true).sql("...").end(); ``` 启用enableFilter后,会自动利用`IServiceContext.bindingCtx()`获取当前上下文中的IServiceContext,并调用`IDataAuthChecker.getFilter()` @@ -338,7 +339,7 @@ OrmSessionFactory支持IEntityFilterProvider配置,nop-auth-service模块提 ### allowUnderscoreName设置为true,将会允许在EQL中直接使用数据库字段名 -``` +```xml select o.statusId, o.status_id from MyEntity o @@ -350,6 +351,6 @@ OrmSessionFactory支持IEntityFilterProvider配置,nop-auth-service模块提 也可以使用在构造SQL对象时直接指定allowUnderscoreName属性 -```javascript - SQL.begin().allowUnderscoreName(true).sql("....").end(); +```java +SQL.begin().allowUnderscoreName(true).sql("....").end(); ``` diff --git a/docs/dev-guide/recipe/filter-list.md b/docs/dev-guide/recipe/filter-list.md index 72b8f6013..b3b53ee13 100644 --- a/docs/dev-guide/recipe/filter-list.md +++ b/docs/dev-guide/recipe/filter-list.md @@ -33,7 +33,7 @@ XView模型中定义的grid可以配置filter条件,使用该grid生成的表格查询数据时会自动携带过滤条件。 -``` +```xml ... @@ -51,7 +51,7 @@ XView模型中定义的grid可以配置filter条件,使用该grid生成的表 xmeta配置文件中可以配置filter过滤条件。如果在meta中配置,则新增、修改的时候也会按照这里的过滤条件自动设置。例如 -``` +```xml @@ -61,7 +61,7 @@ xmeta配置文件中可以配置filter过滤条件。如果在meta中配置, 基于已有的xmeta,可以新建xmeta。例如 MyEntity\_ext.xmeta -``` +```xml @@ -71,7 +71,7 @@ xmeta配置文件中可以配置filter过滤条件。如果在meta中配置, 前台调用时使用对象名`MyEntity_ext`就会自动应用这里的meta。例如 -``` +```graphql query{ MyEntity_ext__findPage{ ... @@ -83,7 +83,7 @@ query{ ## 4. 在后台BizModel中增加新的方法 -``` +```java class MyEntityBizModel extends CrudBizModel{ @BizQuery @GraphQLReturn(bizObjName = BIZ_OBJ_NAME_THIS_OBJ) @@ -103,7 +103,7 @@ class MyEntityBizModel extends CrudBizModel{ 在前台可以继承已有的页面,然后定制其中的api数据请求链接 -``` +```xml
@@ -126,7 +126,10 @@ class MyEntityBizModel extends CrudBizModel{ - o.id in (select t.task.id from MyTask t where t.userId = ${$context.userId || '1'}) + o.id in ( + select t.task.id from MyTask t + where t.userId = ${ $context.userId || '1' } + ) ``` @@ -137,7 +140,10 @@ class MyEntityBizModel extends CrudBizModel{ ```sql o.type = 3 -and o.id in (select t.task.id from MyTask t where t.userId = ${$context.userId || '1'}) +and o.id in ( + select t.task.id from MyTask t + where t.userId = ${ $context.userId || '1' } +) ``` > sql节点的value属性必须是SQL类型,不能是简单的文本字符串,这样约定的目的是避免前台提交filter查询条件插入子查询形成SQL注入攻击。要求value必须是SQL类型,就只能是在后台通过程序来构造。 @@ -241,10 +247,7 @@ QueryBean提供了transformFilter函数,可以对前台提交的查询条件 ```xml - - exists(select o2 from NopAuthResource o2 where o2.siteId= o.id - and o2.status >= ${filter.getAttr('value')}) - + ``` diff --git a/docs/tutorial/simple/4-complex-query.md b/docs/tutorial/simple/4-complex-query.md index c62f6257f..880ad86df 100644 --- a/docs/tutorial/simple/4-complex-query.md +++ b/docs/tutorial/simple/4-complex-query.md @@ -217,8 +217,9 @@ query($filter1:Map, $filter2: Map){ - exists(select o2 from NopAuthResource o2 where o2.siteId= o.id - and o2.status >= ${filter.getAttr('value')}) + exists( select o2 from NopAuthResource o2 where o2.siteId= o.id + and o2.status >= ${ filter.getAttr('value') } + ) @@ -234,6 +235,7 @@ query($filter1:Map, $filter2: Map){ select o from NopAuthSite o where - exists(select o2 from NopAuthResource o2 where o2.siteId= o.id - and o2.status >= 'main' }) + exists( select o2 from NopAuthResource o2 where o2.siteId= o.id + and o2.status >= 'main' + ) ``` From b5b1aa713291267d214e7b158e74a2387ad93e55 Mon Sep 17 00:00:00 2001 From: flytreeleft Date: Wed, 31 Jul 2024 18:07:27 +0800 Subject: [PATCH 5/5] =?UTF-8?q?Docs:=20=E8=BF=98=E5=8E=9F=E8=AF=AF?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/dev-guide/recipe/filter-list.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/dev-guide/recipe/filter-list.md b/docs/dev-guide/recipe/filter-list.md index b3b53ee13..003c567b4 100644 --- a/docs/dev-guide/recipe/filter-list.md +++ b/docs/dev-guide/recipe/filter-list.md @@ -247,7 +247,11 @@ QueryBean提供了transformFilter函数,可以对前台提交的查询条件 ```xml - + + exists( select o2 from NopAuthResource o2 where o2.siteId= o.id + and o2.status >= ${ filter.getAttr('value') } + ) + ```