ArgumentError (неверный аргумент: nil) в Rails / GraphQL - PullRequest
0 голосов
/ 26 июня 2018

Так что я работаю над созданием приложения на основе HowToGraphQL и застрял на фильтрации приложения. Я получаю

ArgumentError (invalid argument: nil.):
app/graphql/resolvers/items_search.rb:26:in 'apply_filter'

Мой items_search.rb выглядит так:

require 'search_object/plugin/graphql'

class Resolvers::ItemsSearch
  include SearchObject.module(:graphql)

  scope { InventoryItem.all }

  # return type
  type !types[Types::InventoryItemType]

  InventoryItemFilter = GraphQL::InputObjectType.define do
    name 'InventoryItemFilter'
    argument :OR, -> { types[InventoryItemFilter] }
    argument :material_contains, types.String
    # argument :balance, !types.Int
    # argument :age, !types.Int
    # argument :width, !types.Int
    argument :roll_number_contains, types.String
    argument :dye_number_contains, types.String
  end

  option :filter, type: InventoryItemFilter, with: :apply_filter

  def apply_filter(scope, value)
    branches = normalize_filters(value).reduce { |a, b| a.or(b) }
    scope.merge(branches)
  end

  def normalize_filters(value, branches = [])
    # add like SQL conditions
    scope = InventoryItem.all
    scope = scope.where('material LIKE ?', "%#{value['material_contains']}%") if value['material_contains']
    scope = scope.where('roll_number LIKE ?', "%#{value['roll_number_contains']}%") if value['roll_number_contains']
    scope = scope.where('dye_number LIKE ?', "%#{value['dye_number_contains']}%") if value['dye_number_contains']

    # continue to normalize down
    value['OR'].reduce(branches) { |s, v| normalize_filters(v, s) } if value['OR'].present?

    branches
  end
end

Понятия не имею, что выдает неверный аргумент: хотя ноль.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...