Class: GraphQL::NonNullType

Inherits:
BaseType show all
Includes:
BaseType::ModifiesAnotherType
Defined in:
lib/graphql/non_null_type.rb

Overview

A non-null 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

#==, #connection_type, #define_connection, #define_edge, #edge_type, #get_field, resolve_related_type, #resolve_type, #to_list_type, #to_non_null_type, #unwrap

Methods included from Define::InstanceDefinable

#definition_proc=, included, #metadata

Methods included from Define::NonNullWithBang

#!

Constructor Details

#initialize(of_type:) ⇒ NonNullType

Returns a new instance of NonNullType.



9
10
11
# File 'lib/graphql/non_null_type.rb', line 9

def initialize(of_type:)
  @of_type = of_type
end

Instance Attribute Details

#of_typeObject (readonly)

Returns the value of attribute of_type.



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

def of_type
  @of_type
end

Instance Method Details

#coerce_input(value) ⇒ Object



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

def coerce_input(value)
  of_type.coerce_input(value)
end

#kindObject



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

def kind
  GraphQL::TypeKinds::NON_NULL
end

#nameObject



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

def name
  "Non-Null"
end

#to_sObject



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

def to_s
  "#{of_type.to_s}!"
end

#valid_input?(value) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid_input?(value)
  validate_input(value).valid?
end

#validate_input(value) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/graphql/non_null_type.rb', line 21

def validate_input(value)
  if value.nil?
    result = GraphQL::Query::InputValidationResult.new
    result.add_problem("Expected value to not be null")
    result
  else
    of_type.validate_input(value)
  end
end