【发布时间】:2018-10-27 09:41:18
【问题描述】:
我的架构文件中定义了以下联合:
union ContentUnion = Content | Setting | Page | Picture
例如 Setting
的这种类型定义type Setting {
id: String!
doctype: String!
name: String!
}
我还有一个适用于 ContentUnion 的类型解析器。
使用这个查询
{
content(id: "113804"){
... on Setting{
id
}
}
}
我能够检索一个值。但这对我来说感觉很奇怪,因为我不明白为什么我必须明确指出 Type 是 Setting。我认为这就是 TypeResolver 的实际用途?
我想简单地使用这个查询
{
content(id: "113804"){
id
}
}
但结果是:
{
"data": null,
"errors": [
{
"message": "Validation error of type FieldUndefined: Field 'id' in type 'ContentUnion' is undefined @ 'content/id'",
"locations": [
{
"line": 1,
"column": 26
}
],
"description": "Field 'id' in type 'ContentUnion' is undefined",
"validationErrorType": "FieldUndefined",
"queryPath": [
"content",
"id"
],
"errorType": "ValidationError",
"path": null,
"extensions": null
}
],
"extensions": null,
"dataPresent": false
}
这是因为架构无法在 ContentUnion 联合类型上找到 id 字段,因为它是一个联合。我想知道是否有办法让它工作?因为它会在我的实现中为我消除很多头痛。
【问题讨论】:
标签: java graphql-java