Class: GraphQL::Schema::List
- Includes:
- Member::ValidatesInput
- Defined in:
- lib/graphql/schema/list.rb
Overview
Represents a list type in the schema. Wraps a Schema::Member as a list type. See Schema::Member::TypeSystemHelpers#to_list_type Create a list type from another GraphQL type
Instance Attribute Summary
Attributes inherited from Wrapper
Instance Method Summary collapse
- #authorizes?(ctx) ⇒ Boolean
- #coerce_input(value, ctx) ⇒ Object
- #coerce_result(value, ctx) ⇒ Object
-
#description ⇒ Object
Also for implementing introspection.
-
#graphql_name ⇒ Object
This is for introspection, where it's expected the name will be
null. -
#kind ⇒ Object
Returns.
-
#list? ⇒ Boolean
Returns.
- #to_type_signature ⇒ Object
- #validate_non_null_input(value, ctx, max_errors: nil) ⇒ Object
Methods included from Member::ValidatesInput
#coerce_isolated_input, #coerce_isolated_result, #valid_input?, #valid_isolated_input?, #validate_input
Methods inherited from Wrapper
#==, #deconstruct_keys, #freeze, #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
#authorizes?(ctx) ⇒ Boolean
37 38 39 |
# File 'lib/graphql/schema/list.rb', line 37 def (ctx) of_type.(ctx) end |
#coerce_input(value, ctx) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/graphql/schema/list.rb', line 55 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
51 52 53 |
# File 'lib/graphql/schema/list.rb', line 51 def coerce_result(value, ctx) value.map { |i| i.nil? ? nil : of_type.coerce_result(i, ctx) } end |
#description ⇒ Object
Also for implementing introspection
47 48 49 |
# File 'lib/graphql/schema/list.rb', line 47 def description nil end |
#graphql_name ⇒ Object
This is for introspection, where it's expected the name will be null
42 43 44 |
# File 'lib/graphql/schema/list.rb', line 42 def graphql_name nil end |
#kind ⇒ Object
Returns
GraphQL::TypeKinds::LIST
:call-seq:
kind() -> GraphQL::TypeKinds::LIST
19 20 21 |
# File 'lib/graphql/schema/list.rb', line 19 def kind GraphQL::TypeKinds::LIST end |
#list? ⇒ Boolean
Returns
true
:call-seq:
list?() -> true
29 30 31 |
# File 'lib/graphql/schema/list.rb', line 29 def list? true end |
#to_type_signature ⇒ Object
33 34 35 |
# File 'lib/graphql/schema/list.rb', line 33 def to_type_signature @type_signature ||= -"[#{@of_type.to_type_signature}]" end |
#validate_non_null_input(value, ctx, max_errors: nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/graphql/schema/list.rb', line 64 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 (result) break end max_errors -= 1 end result.merge_result!(index, item_result) end end result.valid? ? nil : result end |