Skip to content

Commit

Permalink
修正GraphQL的返回类型设置, 没有设置type时根据stdDomain猜测
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Aug 9, 2024
1 parent d007d15 commit 1036c08
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@
/nop/report/xlib/xpt-rt.xlib
/nop/report/xlib/xpt.xlib
/nop/rpc/imp/api.imp.xml
/nop/rpc/imp/api.imp.xml.rej
/nop/rpc/imp/template.api.xlsx
/nop/rule/_module
/nop/rule/auth/_nop-rule-api.action-auth.xml
Expand Down Expand Up @@ -1049,6 +1050,7 @@
/nop/web/xlib/view-gen.xlib
/nop/web/xlib/view-gen/impl_GenFromMeta.xpl
/nop/web/xlib/web.xlib
/nop/web/xlib/web.xlib.rej
/nop/web/xlib/web/grid_crud.xpl
/nop/web/xlib/web/impl_GenForm.xpl
/nop/web/xlib/web/impl_GenGrid.xpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.nop.graphql.core.schema.TypeRegistry;
import io.nop.graphql.core.utils.GraphQLObjMetaHelper;
import io.nop.graphql.core.utils.GraphQLTypeHelper;
import io.nop.xlang.xdef.domain.StdDomainRegistry;
import io.nop.xlang.xmeta.IObjMeta;
import io.nop.xlang.xmeta.IObjPropMeta;
import io.nop.xlang.xmeta.ISchema;
Expand Down Expand Up @@ -195,12 +196,15 @@ public GraphQLType toGraphQLType(String thisObjName, ISchema schema, boolean man
if (bizObjName != null)
return GraphQLTypeHelper.namedType(bizObjName);

StdDataType stdDataType = schema.getStdDataType();
if (stdDataType != null)
gqlType = GraphQLTypeHelper.scalarType(GraphQLScalarType.fromStdDataType(stdDataType));
if (gqlType == null)
gqlType = GraphQLTypeHelper.scalarType(GraphQLScalarType.String);
return gqlType;
type = guessType(schema);
if (type == null) {
StdDataType stdDataType = schema.getStdDataType();
if (stdDataType != null)
gqlType = GraphQLTypeHelper.scalarType(GraphQLScalarType.fromStdDataType(stdDataType));
if (gqlType == null)
gqlType = GraphQLTypeHelper.scalarType(GraphQLScalarType.String);
return gqlType;
}
}
gqlType = ReflectionGraphQLTypeFactory.INSTANCE.buildGraphQLType(type, thisObjName, bizObjName,
typeRegistry, input);
Expand All @@ -213,6 +217,13 @@ public GraphQLType toGraphQLType(String thisObjName, ISchema schema, boolean man
return gqlType;
}

IGenericType guessType(ISchema schema) {
String stdDomain = schema.getStdDomain();
if (stdDomain == null)
return null;
return StdDomainRegistry.instance().getStdDomainHandler(stdDomain).getGenericType(false, null);
}

private GraphQLType buildObjType(String thisObjName, ISchema schema, TypeRegistry registry, boolean input) {
GraphQLObjectDefinition def = new GraphQLObjectDefinition();
def.setLocation(schema.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@ private void printArgDefs(List<GraphQLArgumentDefinition> args) {
public void visitGraphQLArgumentDefinition(GraphQLArgumentDefinition node) {
out.append(node.getName());
out.append(':');
visit(node.getType());
if(node.getType() == null){
out.append("Any");
}else {
visit(node.getType());
}
if (node.getDefaultValue() != null) {
out.append(" = ");
visit(node.getDefaultValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</prop>

<prop name="beforeExecute" displayName="初始化代码" ui:show="L" insertable="true" updatable="true">
<schema stdDomain="xpl"/>
<schema stdDomain="xpl" type="String"/>
</prop>

<prop name="importFile" displayName="Excel规则文件" published="false" updatable="false" insertable="false"
Expand All @@ -31,7 +31,7 @@
</prop>

<prop name="decisionMatrix" displayName="决策矩阵配置" ui:show="L" insertable="true" updatable="true">
<schema stdDomain="xml"/>
<schema stdDomain="xml" type="String"/>
</prop>
</props>
</meta>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</prop>

<prop name="defaultExpr" displayName="缺省值" insertable="true" updatable="true">
<schema stdDomain="xpl"/>
<schema stdDomain="xpl" type="String"/>
</prop>

<prop name="description" displayName="描述" insertable="true" updatable="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</prop>

<prop name="valueExpr" displayName="变量表达式" mandatory="true">
<schema stdDomain="xpl"/>
<schema stdDomain="xpl" type="String"/>
</prop>
</props>
</meta>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<actions>
<query name="getOutputFieldsEditSchema">
<arg name="ruleId" mandatory="true" />
<arg name="ruleId" mandatory="true" type="String" />
<arg name="selection" kind="FieldSelection"/>
<arg name="svcCtx" kind="ServiceContext" />

Expand Down

0 comments on commit 1036c08

Please sign in to comment.