From dee2cd5c720c70e0a8231c437a010eed5033ebf1 Mon Sep 17 00:00:00 2001 From: canonical Date: Wed, 22 Jan 2025 22:18:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0graphql=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89type=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/dev-guide/graphql/graphql-type.md | 61 ++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/docs/dev-guide/graphql/graphql-type.md b/docs/dev-guide/graphql/graphql-type.md index 3faa94103..9f2e46996 100644 --- a/docs/dev-guide/graphql/graphql-type.md +++ b/docs/dev-guide/graphql/graphql-type.md @@ -28,3 +28,64 @@ class ResultBean { } } ``` + +## 使用XBiz来定义动态GraphQL类型 + +通过return的schema配置,可以定义GraphQL类型。 + +```xml + + + + + + + + import io.nop.auth.service.biz.ItemData; + + const ret = new ItemData(); + ret.name = "a"; + ret.rows = []; + return ret; + + +``` + +通过`x:extends`可以复用已有的schema定义。 + +```xml + + + + + + + + + + + + + + + +``` + +上面的示例中rows和rows2的定义在GraphQL层面产生的类型是一样的。 + +## 通过graphql文件引入类型定义。 +通过`nop.graphql.builtin-schema-path`可以指定多个graphql虚拟文件路径,这些文件中的类型定义会被自动引入到GraphQL中。 + +```graphql +type UserItemData{ + name:String + rows:[UserItemData] +} +``` +然后在xbiz中就可以直接使用这个类型名 + +```xml + + + +```