Class: GraphQL::Schema::List

Inherits:
Wrapper
  • Object
show all
Includes:
Member::ValidatesInput
Defined in:
lib/graphql/schema/list.rb

Overview

Represents a list type in the schema. Wraps a Member as a list type.

See Also:

  • {Schema{Schema::Member{Schema::Member::TypeSystemHelpers{Schema::Member::TypeSystemHelpers#to_list_type}

Instance Attribute Summary

Attributes inherited from Wrapper

#of_type

Instance Method Summary collapse

Methods included from Member::ValidatesInput

#coerce_isolated_input, #coerce_isolated_result, #valid_input?, #valid_isolated_input?, #validate_input

Methods inherited from Wrapper

#==, #initialize, #unwrap

Methods included from Member::TypeSystemHelpers

#non_null?, #to_list_type, #to_non_null_type

Methods included from Member::CachedGraphQLDefinition

#graphql_definition, #initialize_copy, #type_class

Constructor Details

This class inherits a constructor from GraphQL::Schema::Wrapper

Instance Method Details

#coerce_input(value, ctx) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/graphql/schema/list.rb', line 43

def coerce_input(value, ctx)
  if value.nil?
    nil
  else
    coerced = ensure_array(value).map { |item| item.nil? ? item : of_type.coerce_input(item, ctx) }
    ctx.schema.after_any_lazies(coerced, &:itself)
  end
end

#coerce_result(value, ctx) ⇒ Object



39
40
41
# File 'lib/graphql/schema/list.rb', line 39

def coerce_result(value, ctx)
  value.map { |i| i.nil? ? nil : of_type.coerce_result(i, ctx) }
end

#descriptionObject

Also for implementing introspection



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

def description
  nil
end

#graphql_nameObject

This is for introspection, where it’s expected the name will be null



30
31
32
# File 'lib/graphql/schema/list.rb', line 30

def graphql_name
  nil
end

#kindGraphQL::TypeKinds::LIST

Returns:

  • (GraphQL::TypeKinds::LIST)


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

def kind
  GraphQL::TypeKinds::LIST
end

#list?true

Returns:

  • (true)


21
22
23
# File 'lib/graphql/schema/list.rb', line 21

def list?
  true
end

#to_graphqlObject



11
12
13
# File 'lib/graphql/schema/list.rb', line 11

def to_graphql
  @of_type.graphql_definition.to_list_type
end

#to_type_signatureObject



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

def to_type_signature
  "[#{@of_type.to_type_signature}]"
end

#validate_non_null_input(value, ctx) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/graphql/schema/list.rb', line 52

def validate_non_null_input(value, ctx)
  result = GraphQL::Query::InputValidationResult.new
  ensure_array(value).each_with_index do |item, index|
    item_result = of_type.validate_input(item, ctx)
    if !item_result.valid?
      result.merge_result!(index, item_result)
    end
  end
  result
end