Class: GraphQL::ScalarType

Inherits:
BaseType show all
Defined in:
lib/graphql/scalar_type.rb

Defined Under Namespace

Modules: NoOpCoerce

Instance Attribute Summary

Attributes inherited from BaseType

#ast_node, #default_relay, #default_scalar, #description, #introspection, #name

Instance Method Summary collapse

Methods inherited from BaseType

#==, #coerce_input, #coerce_isolated_input, #coerce_isolated_result, #default_relay?, #default_scalar?, #get_field, #initialize_copy, #introspection?, #list?, #non_null?, resolve_related_type, #resolve_type, #to_definition, #to_list_type, #to_non_null_type, #to_s, #type_class, #unwrap, #valid_input?, #valid_isolated_input?, #validate_input, #validate_isolated_input

Methods included from Relay::TypeExtensions

#connection_type, #define_connection, #define_edge, #edge_type

Methods included from Define::InstanceDefinable

#define, #initialize_copy, #metadata, #redefine

Methods included from Define::NonNullWithBang

#!

Constructor Details

#initializeScalarType

Returns a new instance of ScalarType.


14
15
16
17
# File 'lib/graphql/scalar_type.rb', line 14

def initialize
  super
  self.coerce = NoOpCoerce
end

Instance Method Details

#coerce=(proc) ⇒ Object


19
20
21
22
# File 'lib/graphql/scalar_type.rb', line 19

def coerce=(proc)
  self.coerce_input = proc
  self.coerce_result = proc
end

#coerce_input=(coerce_input_fn) ⇒ Object


24
25
26
27
28
# File 'lib/graphql/scalar_type.rb', line 24

def coerce_input=(coerce_input_fn)
  if !coerce_input_fn.nil?
    @coerce_input_proc = ensure_two_arg(coerce_input_fn, :coerce_input)
  end
end

#coerce_result(value, ctx = nil) ⇒ Object


30
31
32
33
34
35
36
# File 'lib/graphql/scalar_type.rb', line 30

def coerce_result(value, ctx = nil)
  if ctx.nil?
    warn_deprecated_coerce("coerce_isolated_result")
    ctx = GraphQL::Query::NullContext
  end
  @coerce_result_proc.call(value, ctx)
end

#coerce_result=(coerce_result_fn) ⇒ Object


38
39
40
41
42
# File 'lib/graphql/scalar_type.rb', line 38

def coerce_result=(coerce_result_fn)
  if !coerce_result_fn.nil?
    @coerce_result_proc = ensure_two_arg(coerce_result_fn, :coerce_result)
  end
end

#kindObject


44
45
46
# File 'lib/graphql/scalar_type.rb', line 44

def kind
  GraphQL::TypeKinds::SCALAR
end