我的 GraphQL 架构是:
//Schema generated from query classes
GraphQLSchema schema = new GraphQLSchemaGenerator()
.withBasePackages("com.blah.blah")
.withOperationBuilder(new DefaultOperationBuilder(DefaultOperationBuilder.TypeInference.UNLIMITED))
.withOutputConverters((config, defaults) -> defaults.drop(ObjectScalarAdapter.class))
.withResolverBuilders(new AnnotatedResolverBuilder())
.withOperationsFromSingleton(myObjectQuery)
.withTypeTransformer(new DefaultTypeTransformer(true, true))
.withValueMapperFactory(new JacksonValueMapperFactory())
.generate();
我定义了一个 GraphQLQuery:
@GraphQLQuery(name = "getMyObject")
public MyObject getMyObject() {}
它返回一个“MyObject”类
MyObject 类不使用泛型,定义如下(我无法更改),尽管我知道myList包含MyListType类型的对象:
public class MyObject {
private List myList;
public List getMyList() {
return myList;
}
}
使用 Graph i QL(假设字段有效):
{
getMyObject() {
id
myList{
myListTypeId
}
}
}
结果是:
{
"errors": [
{
"message": "Validation error of type SubSelectionNotAllowed: Sub selection not allowed on leaf type null of field myList@ 'getMyObject/myList'",
"locations": [
{
"line": 4,
"column": 5
}
]
}
]
}
如何解决此错误?我添加了一个方面来强制 getMylist() 的返回结果成为一个 List,但显然这对验证步骤没有影响。
问题是:如何配置架构以允许返回非泛型列表或映射的 getter?