Class: GraphQL::Client::Schema::ScalarType

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

Instance Attribute Summary

Attributes included from BaseType

#schema_module, #type

Instance Method Summary collapse

Methods included from BaseType

#to_list_type, #to_non_null_type

Constructor Details

#initialize(type) ⇒ ScalarType

Internal: Construct type wrapper from another GraphQL::BaseType.

type - GraphQL::BaseType instance



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

def initialize(type)
  unless type.is_a?(GraphQL::ScalarType)
    raise "expected type to be a GraphQL::ScalarType, but was #{type.class}"
  end

  @type = type
end

Instance Method Details

#cast(value, _errors = nil) ⇒ Object

Internal: Cast raw JSON value to Ruby scalar object.

value - JSON value errors - Errors instance

Returns casted Object.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/graphql/client/schema/scalar_type.rb', line 32

def cast(value, _errors = nil)
  case value
  when NilClass
    nil
  else
    if type.respond_to?(:coerce_isolated_input)
      type.coerce_isolated_input(value)
    else
      type.coerce_input(value)
    end
  end
end

#define_class(definition, ast_nodes) ⇒ Object



22
23
24
# File 'lib/graphql/client/schema/scalar_type.rb', line 22

def define_class(definition, ast_nodes)
  self
end