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

#initialize, #non_null?, #to_list_type, #to_non_null_type

Constructor Details

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

Instance Method Details

#coerce_input(value, ctx) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/graphql/schema/list.rb', line 39

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



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

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

#descriptionObject

Also for implementing introspection



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

def description
  nil
end

#graphql_nameObject

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



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

def graphql_name
  nil
end

#kindGraphQL::TypeKinds::LIST

Returns:

  • (GraphQL::TypeKinds::LIST)


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

def kind
  GraphQL::TypeKinds::LIST
end

#list?true

Returns:

  • (true)


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

def list?
  true
end

#to_type_signatureObject



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

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

#validate_non_null_input(value, ctx, max_errors: nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/graphql/schema/list.rb', line 48

def validate_non_null_input(value, ctx, max_errors: nil)
  result = GraphQL::Query::InputValidationResult.new
  ensure_array(value).each_with_index do |item, index|
    item_result = of_type.validate_input(item, ctx)
    unless item_result.valid?
      if max_errors
        if max_errors == 0
          add_max_errros_reached_message(result)
          break
        end

        max_errors -= 1
      end

      result.merge_result!(index, item_result)
    end
  end
  result.valid? ? nil : result
end