ruby-on-rails - 带有数组字段的 GraphQL ObjectType 返回 null
问题描述
我有一个字段是我想在解析器中定义的数组。问题是,我的结果不返回作为数组的字段,而只是一个具有空值的对象。
field :pies do
type types[Types::OutputType]
resolve -> (_obj, _args, ctx){
pies = []
CookBook.pages.each do |page|
labels = []
labels << OpenStruct.new(
id: 1,
name: "blueberry"
)
pie = OpenStruct.new(
id: 1,
labels: labels
)
pies << pie
end
pies
}
end
Types::OutputType = GraphQL::ObjectType.define do
name 'OutputType'
field :id, types.ID
field :labels, types[Types::LabelType]
end
Types::LabelType = GraphQL::ObjectType.define do
name 'LabelType'
field :id, types.ID!
field :name, types.String
end
这是查询:
# Write your query or mutation here
{
pies{
id,
labels{
name
}
}
}
这是结果:
{
"data": {
"pies": [
{
"id": "9",
"labels": {
"name": null
}
},
{
"id": "3",
"labels": {
"name": null
}
},
...
]
}
}
为什么我的标签字段不返回数组而只返回带有空值的对象?
解决方案
推荐阅读
- c# - 获取给定对话 ID 的令牌
- javascript - 如何将 CKEditor textarea 与字符限制集成?
- angular - 添加新元素时,角度更新现有 FormArray 元素的有效性
- python - sklearn KNeighborsClassifier 评分方法如何工作?
- php - 我正在尝试使用 php file() 并从另一个目录中提取并在文件名中使用 *
- javascript - 如何使用swift3从alamofire响应中获取字典数组的值
- optaplanner - 任务分配示例的领域模型推理不清楚
- node.js - bundle.js 没有被创建
- c# - 在 Visual Studio 中导入正确的模块 - Powershell cmdlet
- angular - 在 Angular 教程中出现无法找到名称“HEROES”错误