Class: GraphQL::ListType

Inherits:
BaseType show all
Includes:
BaseType::ModifiesAnotherType
Defined in:
lib/graphql/list_type.rb

Overview

A list type wraps another type.

Get the underlying type with BaseType::ModifiesAnotherType#unwrap

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseType::ModifiesAnotherType

#unwrap

Methods inherited from BaseType

#==, #coerce_input, #connection_type, #define_connection, #define_edge, #edge_type, #get_field, resolve_related_type, #resolve_type, #to_list_type, #to_non_null_type, #unwrap, #valid_input?, #validate_input

Methods included from Define::InstanceDefinable

#definition_proc=, included, #metadata

Methods included from Define::NonNullWithBang

#!

Constructor Details

#initialize(of_type:) ⇒ ListType

Returns a new instance of ListType.



8
9
10
11
# File 'lib/graphql/list_type.rb', line 8

def initialize(of_type:)
  @name = "List"
  @of_type = of_type
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/graphql/list_type.rb', line 7

def name
  @name
end

#of_typeObject (readonly)

Returns the value of attribute of_type.



7
8
9
# File 'lib/graphql/list_type.rb', line 7

def of_type
  @of_type
end

Instance Method Details

#coerce_non_null_input(value) ⇒ Object



35
36
37
# File 'lib/graphql/list_type.rb', line 35

def coerce_non_null_input(value)
  ensure_array(value).map{ |item| of_type.coerce_input(item) }
end

#kindObject



13
14
15
# File 'lib/graphql/list_type.rb', line 13

def kind
  GraphQL::TypeKinds::LIST
end

#to_sObject



17
18
19
# File 'lib/graphql/list_type.rb', line 17

def to_s
  "[#{of_type.to_s}]"
end

#validate_non_null_input(value) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/graphql/list_type.rb', line 21

def validate_non_null_input(value)
  result = GraphQL::Query::InputValidationResult.new

  ensure_array(value).each_with_index do |item, index|
    item_result = of_type.validate_input(item)
    if !item_result.valid?
      result.merge_result!(index, item_result)
    end
  end

  result
end