Class: Rails::GraphQL::Type::Scalar::FloatScalar

Inherits:
Rails::GraphQL::Type::Scalar show all
Defined in:
lib/rails/graphql/type/scalar/float_scalar.rb

Overview

The Float scalar type represents signed double-precision fractional values as specified by IEEE 754.

See spec.graphql.org/June2018/#sec-Float

Direct Known Subclasses

TimeScalar

Constant Summary

Constants inherited from Rails::GraphQL::Type

KINDS

Class Method Summary collapse

Methods inherited from Rails::GraphQL::Type::Scalar

deserialize, inspect, to_json

Methods inherited from Rails::GraphQL::Type

=~, base_type, create!, decorate, find_by_gid, gid_base_class, input_type?, kind, kind_enum, leaf_type?, operational?, output_type?, to_gql_backtrace

Methods included from Helpers::WithDirectives

#all_directive_events, #all_directive_listeners, #directive_events?, #directive_listeners?, extended, included, #initialize_copy, #use, #using?, #validate!

Methods included from Helpers::WithGlobalID

#to_gid_param, #to_global_id

Methods included from Helpers::Registerable

#aliases, extended, #inherited, #register!, #registered?

Class Method Details

.as_json(value) ⇒ Object



25
26
27
# File 'lib/rails/graphql/type/scalar/float_scalar.rb', line 25

def as_json(value)
  value.to_f
end

.valid_input?(value) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rails/graphql/type/scalar/float_scalar.rb', line 17

def valid_input?(value)
  valid_token?(value) || value.is_a?(Float)
end

.valid_output?(value) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rails/graphql/type/scalar/float_scalar.rb', line 21

def valid_output?(value)
  value.respond_to?(:to_f)
end