Class: GraphQL::Client::Schema::ListType

Inherits:
Object
  • Object
show all
Includes:
BaseType
Defined in:
lib/graphql/client/schema/list_type.rb

Instance Attribute Summary collapse

Attributes included from BaseType

#schema_module, #type

Instance Method Summary collapse

Methods included from BaseType

#to_non_null_type

Constructor Details

#initialize(of_klass) ⇒ ListType

Internal: Construct list wrapper from other BaseType.

of_klass - BaseType instance


16
17
18
19
20
21
22
# File 'lib/graphql/client/schema/list_type.rb', line 16

def initialize(of_klass)
  unless of_klass.is_a?(BaseType)
    raise TypeError, "expected #{of_klass.inspect} to be a #{BaseType}"
  end

  @of_klass = of_klass
end

Instance Attribute Details

#of_klassObject (readonly)

Internal: Get wrapped klass.

Returns BaseType instance.


27
28
29
# File 'lib/graphql/client/schema/list_type.rb', line 27

def of_klass
  @of_klass
end

Instance Method Details

#cast(values, errors) ⇒ Object

Internal: Cast JSON value to wrapped value.

values - JSON value errors - Errors instance

Returns List instance or nil.


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/graphql/client/schema/list_type.rb', line 35

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

#to_list_typeObject

Internal: Get list wrapper of this type class.

Returns ListType instance.


51
52
53
# File 'lib/graphql/client/schema/list_type.rb', line 51

def to_list_type
  self
end