1

我有一个字段是我想在解析器中定义的数组。问题是,我的结果不返回作为数组的字段,而只是一个具有空值的对象。


  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
        }
      },
      ...
    ]
  }
}

为什么我的标签字段不返回数组而只返回带有空值的对象?

4

0 回答 0