Class: GraphQL::Client::Schema::ScalarType
- Inherits:
-
Object
- Object
- GraphQL::Client::Schema::ScalarType
- Includes:
- BaseType
- Defined in:
- lib/graphql/client/schema/scalar_type.rb
Instance Attribute Summary
Attributes included from BaseType
Instance Method Summary collapse
-
#cast(value, _errors = nil) ⇒ Object
Internal: Cast raw JSON value to Ruby scalar object.
- #define_class(definition, ast_nodes) ⇒ Object
-
#initialize(type) ⇒ ScalarType
constructor
Internal: Construct type wrapper from another GraphQL::BaseType.
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.kind.scalar? raise "expected type to be a Scalar, 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 |