Class: GraphQL::Client::Schema::NonNullType

Inherits:
Object
  • Object
show all
Includes:
BaseType
Defined in:
lib/graphql/client/schema/non_null_type.rb

Instance Attribute Summary collapse

Attributes included from BaseType

#schema_module, #type

Instance Method Summary collapse

Methods included from BaseType

#to_list_type

Constructor Details

#initialize(of_klass) ⇒ NonNullType

Internal: Construct non-nullable wrapper from other BaseType.

of_klass - BaseType instance


15
16
17
18
19
20
21
# File 'lib/graphql/client/schema/non_null_type.rb', line 15

def initialize(of_klass)
  unless of_klass.is_a?(BaseType)
    raise TypeError, "expected #{of_klass.inspect} to be a #{BaseType}"
  end

  @of_klass = of_klass
end

Instance Attribute Details

#of_klassObject (readonly)

Internal: Get wrapped klass.

Returns BaseType instance.


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

def of_klass
  @of_klass
end

Instance Method Details

#cast(value, errors) ⇒ Object

Internal: Cast JSON value to wrapped value.

value - JSON value errors - Errors instance

Returns BaseType instance.


34
35
36
37
38
39
40
41
# File 'lib/graphql/client/schema/non_null_type.rb', line 34

def cast(value, errors)
  case value
  when NilClass
    raise InvariantError, "expected value to be non-nullable, but was nil"
  else
    of_klass.cast(value, errors)
  end
end

#to_non_null_typeObject

Internal: Get non-nullable wrapper of this type class.

Returns NonNullType instance.


46
47
48
# File 'lib/graphql/client/schema/non_null_type.rb', line 46

def to_non_null_type
  self
end