我是 GraphQL 的新手,想知道是否有人可以帮我弄清楚以下 JSON 到 GraphQL 模式中的等价物:
[
{
"id": "1",
"name": "A",
"fldDef": [
{
"name": "f1",
"type": "str",
"opt": false
},
{
"name": "f2",
"type": "bool"
}]
},
{
"id": "2",
"name": "B",
"fldDef": [
{
"name": "f3",
"type": "str",
"opt": true
},
{
"name": "f4",
"type": "str",
"opt": true
}]
}
]
到目前为止,我设法将以上响应映射到以下对象:
public class FldDef {
private String name, type;
private boolean opt;
// getters & setters
}
public class Product {
private String id, name;
private Map<String, FldDef> fldDef;
// getters & setters
}
然后我的架构如下所示,但我遇到的问题是作为Product
对象的一部分,我有一个Map
我想获得适合它的架构,但我很难获得正确的架构!
type FldDef {
name: String!
type: String!
opt: Boolean!
}
type Product {
id: String!
name: String!
fldDef: FldDef! // now here I don't know what is the syntax for representing MAP, do you know how to achieve this?
}
我得到以下异常:
Causedby:com.coxautodev.graphql.tools.TypeClassMatcher$RawClassRequiredForGraphQLMappingException: Type java.util.Map<java.lang.String, com.grapql.research.domain.FldDef> cannot be mapped to a GraphQL type! Since GraphQL-Java deals with erased types at runtime, only non-parameterized classes can represent a GraphQL type. This allows for reverse-lookup by java class in interfaces and union types.
注意:我正在使用 Java 生态系统 (graphql-java)