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, #resolve_type, #to_list_type, #to_non_null_type, #unwrap, #valid_input?

Methods included from DefinitionHelpers::DefinedByConfig

included

Methods included from DefinitionHelpers::NonNullWithBang

#!

Constructor Details

#initialize(of_type:) ⇒ ListType

Returns a new instance of ListType.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#of_typeObject (readonly)

Returns the value of attribute of_type.



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

def of_type
  @of_type
end

Instance Method Details

#coerce_non_null_input(value) ⇒ Object



25
26
27
# File 'lib/graphql/list_type.rb', line 25

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

#kindObject



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

def kind
  GraphQL::TypeKinds::LIST
end

#to_sObject



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

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

#valid_non_null_input?(value) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/graphql/list_type.rb', line 20

def valid_non_null_input?(value)
  return false unless value.is_a?(Array)
  value.all?{ |item| of_type.valid_input?(item) }
end