From c8730d0b76513d46e3b3c8c920923735c6a583d8 Mon Sep 17 00:00:00 2001 From: canonical Date: Wed, 22 Jan 2025 22:03:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8A=A8=E6=80=81GraphQL?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/nop/auth/service/TestDynamicItem.java | 34 +++++++++++++++++ .../io/nop/auth/service/biz/ItemData.java | 37 +++++++++++++++++++ .../model/NopAuthUser/ItemSchema.schema.xml | 15 ++++++++ .../auth/model/NopAuthUser/NopAuthUser.xbiz | 16 ++++++++ 4 files changed, 102 insertions(+) create mode 100644 nop-auth/nop-auth-service/src/test/java/io/nop/auth/service/TestDynamicItem.java create mode 100644 nop-auth/nop-auth-service/src/test/java/io/nop/auth/service/biz/ItemData.java create mode 100644 nop-auth/nop-auth-service/src/test/resources/_vfs/_delta/default/nop/auth/model/NopAuthUser/ItemSchema.schema.xml diff --git a/nop-auth/nop-auth-service/src/test/java/io/nop/auth/service/TestDynamicItem.java b/nop-auth/nop-auth-service/src/test/java/io/nop/auth/service/TestDynamicItem.java new file mode 100644 index 000000000..74b1739de --- /dev/null +++ b/nop-auth/nop-auth-service/src/test/java/io/nop/auth/service/TestDynamicItem.java @@ -0,0 +1,34 @@ +package io.nop.auth.service; + +import io.nop.api.core.annotations.autotest.NopTestConfig; +import io.nop.api.core.beans.ApiRequest; +import io.nop.autotest.junit.JunitBaseTestCase; +import io.nop.core.model.selection.FieldSelectionBeanParser; +import io.nop.graphql.core.IGraphQLExecutionContext; +import io.nop.graphql.core.ast.GraphQLOperationType; +import io.nop.graphql.core.engine.IGraphQLEngine; +import jakarta.inject.Inject; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@NopTestConfig(localDb = true, initDatabaseSchema = true) +public class TestDynamicItem extends JunitBaseTestCase { + @Inject + IGraphQLEngine graphQLEngine; + + + @Test + public void testDynamicItem() { + ApiRequest> request = new ApiRequest<>(); + request.setData(Map.of("id", "123")); + request.setSelection(FieldSelectionBeanParser.fromText(null, "name, rows{nickName},rows2{userName}")); + + IGraphQLExecutionContext context = graphQLEngine.newRpcContext(GraphQLOperationType.query, + "NopAuthUser__testDynamicItem", request); + Map result = (Map) graphQLEngine.executeRpc(context).get(); + assertEquals("a", result.get("name")); + } +} diff --git a/nop-auth/nop-auth-service/src/test/java/io/nop/auth/service/biz/ItemData.java b/nop-auth/nop-auth-service/src/test/java/io/nop/auth/service/biz/ItemData.java new file mode 100644 index 000000000..6a261ca22 --- /dev/null +++ b/nop-auth/nop-auth-service/src/test/java/io/nop/auth/service/biz/ItemData.java @@ -0,0 +1,37 @@ +package io.nop.auth.service.biz; + +import io.nop.api.core.annotations.data.DataBean; +import io.nop.orm.IOrmEntity; + +import java.util.List; + +@DataBean +public class ItemData { + private String name; + private List rows; + private List rows2; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public List getRows2() { + return rows2; + } + + public void setRows2(List rows2) { + this.rows2 = rows2; + } +} diff --git a/nop-auth/nop-auth-service/src/test/resources/_vfs/_delta/default/nop/auth/model/NopAuthUser/ItemSchema.schema.xml b/nop-auth/nop-auth-service/src/test/resources/_vfs/_delta/default/nop/auth/model/NopAuthUser/ItemSchema.schema.xml new file mode 100644 index 000000000..b71b63943 --- /dev/null +++ b/nop-auth/nop-auth-service/src/test/resources/_vfs/_delta/default/nop/auth/model/NopAuthUser/ItemSchema.schema.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nop-auth/nop-auth-service/src/test/resources/_vfs/_delta/default/nop/auth/model/NopAuthUser/NopAuthUser.xbiz b/nop-auth/nop-auth-service/src/test/resources/_vfs/_delta/default/nop/auth/model/NopAuthUser/NopAuthUser.xbiz index 54805c2d4..54871d318 100644 --- a/nop-auth/nop-auth-service/src/test/resources/_vfs/_delta/default/nop/auth/model/NopAuthUser/NopAuthUser.xbiz +++ b/nop-auth/nop-auth-service/src/test/resources/_vfs/_delta/default/nop/auth/model/NopAuthUser/NopAuthUser.xbiz @@ -27,5 +27,21 @@ + + + + + + + + + import io.nop.auth.service.biz.ItemData; + + const ret = new ItemData(); + ret.name = "a"; + ret.rows = []; + return ret; + + \ No newline at end of file