Class: GraphQL::Schema::List

Inherits:
Wrapper
  • Object
show all
Includes:
Member::CachedGraphQLDefinition::DeprecatedToGraphQL, 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

#deprecated_to_graphql, #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


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

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


41
42
43
# File 'lib/graphql/schema/list.rb', line 41

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

#descriptionObject

Also for implementing introspection


37
38
39
# File 'lib/graphql/schema/list.rb', line 37

def description
  nil
end

#graphql_nameObject

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


32
33
34
# File 'lib/graphql/schema/list.rb', line 32

def graphql_name
  nil
end

#kindGraphQL::TypeKinds::LIST

Returns:

  • (GraphQL::TypeKinds::LIST)

18
19
20
# File 'lib/graphql/schema/list.rb', line 18

def kind
  GraphQL::TypeKinds::LIST
end

#list?true

Returns:

  • (true)

23
24
25
# File 'lib/graphql/schema/list.rb', line 23

def list?
  true
end

#to_graphqlObject


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

def to_graphql
  @of_type.graphql_definition(silence_deprecation_warning: true).to_list_type
end

#to_type_signatureObject


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

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

#validate_non_null_input(value, ctx) ⇒ Object


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

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