Array或ObjectType作为参数GraphQL rails

时间:2018-01-18 19:58:44

标签: ruby-on-rails arrays arguments

我需要传递一个ids数组或一组对象。我怎么能通过呢?

field :deleteDispatches, Types::DispatchType do
  argument :route_id, !types.ID
  argument :dispatches_id, ![types.ID] #doesn't work
  argument :dispatches, [Types::DispatchType] #doesn't work

2 个答案:

答案 0 :(得分:1)

您可以使用此代码ids传递argument :dispatches_id, !types[types.ID]数组。

答案 1 :(得分:0)

您需要输入对象进行分派,例如Inputs::DispatchInput

field :deleteDispatches, Types::DispatchType do
  argument :route_id, !types.ID
  argument :dispatches_id, !types[types.ID]
  argument :dispatches, types[Inputs::DispatchInput]

Inputs :: DispatchInput:

# inputs/dispatch_input.rb
module Inputs
  class FilterInput < Types::BaseInputObject
    argument :id, Int, required: true
    argument :name, String, required: false
  end
end