Class: GraphQL::Schema::Scalar

Inherits:
Member
  • Object
show all
Extended by:
Member::AcceptsDefinition, Member::ValidatesInput
Defined in:
lib/graphql/schema/scalar.rb

Constant Summary

Constants included from Member::GraphQLTypeNames

Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int

Class Method Summary collapse

Methods included from Member::ValidatesInput

coerce_isolated_input, coerce_isolated_result, valid_input?, valid_isolated_input?, validate_input

Methods included from Member::HasAstNode

#ast_node

Methods included from Member::HasPath

#path

Methods included from Member::RelayShortcuts

#connection_type, #connection_type_class, #edge_type, #edge_type_class

Methods included from Member::Scoped

#scope_items

Methods included from Member::TypeSystemHelpers

#kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature

Methods included from Member::BaseDSLMethods::ConfigurationExtension

#inherited

Methods included from Member::BaseDSLMethods

#accessible?, #authorized?, #default_graphql_name, #description, #graphql_name, #introspection, #introspection?, #mutation, #name, #overridden_graphql_name, #to_graphql, #visible?

Methods included from Relay::TypeExtensions

#connection_type, #define_connection, #define_edge, #edge_type

Methods included from Member::CachedGraphQLDefinition

#graphql_definition, #initialize_copy, #type_class

Class Method Details

.coerce_input(val, ctx) ⇒ Object



9
10
11
# File 'lib/graphql/schema/scalar.rb', line 9

def coerce_input(val, ctx)
  val
end

.coerce_result(val, ctx) ⇒ Object



13
14
15
# File 'lib/graphql/schema/scalar.rb', line 13

def coerce_result(val, ctx)
  val
end

.default_scalar(is_default = nil) ⇒ Object



33
34
35
36
37
38
# File 'lib/graphql/schema/scalar.rb', line 33

def default_scalar(is_default = nil)
  if !is_default.nil?
    @default_scalar = is_default
  end
  @default_scalar
end

.default_scalar?Boolean

Returns:



40
41
42
# File 'lib/graphql/schema/scalar.rb', line 40

def default_scalar?
  @default_scalar ||= false
end

.kindObject



29
30
31
# File 'lib/graphql/schema/scalar.rb', line 29

def kind
  GraphQL::TypeKinds::SCALAR
end

.to_graphqlObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/graphql/schema/scalar.rb', line 17

def to_graphql
  type_defn = GraphQL::ScalarType.new
  type_defn.name = graphql_name
  type_defn.description = description
  type_defn.coerce_result = method(:coerce_result)
  type_defn.coerce_input = method(:coerce_input)
  type_defn.[:type_class] = self
  type_defn.default_scalar = default_scalar
  type_defn.ast_node = ast_node
  type_defn
end

.validate_non_null_input(value, ctx) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/graphql/schema/scalar.rb', line 44

def validate_non_null_input(value, ctx)
  result = Query::InputValidationResult.new
  coerced_result = begin
    coerce_input(value, ctx)
  rescue GraphQL::CoercionError => err
    err
  end

  if coerced_result.nil?
    str_value = if value == Float::INFINITY
      ""
    else
      " #{GraphQL::Language.serialize(value)}"
    end
    result.add_problem("Could not coerce value#{str_value} to #{graphql_name}")
  elsif coerced_result.is_a?(GraphQL::CoercionError)
    result.add_problem(coerced_result.message, message: coerced_result.message, extensions: coerced_result.extensions)
  end
  result
end