Class: GraphQL::Client::QueryResult::ListWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/client/query_result.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ ListWrapper

Returns a new instance of ListWrapper.



61
62
63
# File 'lib/graphql/client/query_result.rb', line 61

def initialize(type)
  @of_klass = type
end

Instance Method Details

#cast(value, errors) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/graphql/client/query_result.rb', line 65

def cast(value, errors)
  case value
  when Array
    List.new(value.each_with_index.map { |e, idx|
      @of_klass.cast(e, errors.filter_by_path(idx))
    }, errors)
  else
    raise ArgumentError, "expected list value to be an Array, but was #{value.class}"
  end
end

#|(other) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/graphql/client/query_result.rb', line 76

def |(other)
  if self.class == other.class
    self.of_klass | other.of_klass
  else
    raise TypeError, "expected other to be a #{self.class}"
  end
end