Class: GraphQL::Schema::Scalar

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

Constant Summary

Constants included from Member::HasDirectives

Member::HasDirectives::NO_DIRECTIVES

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::BaseDSLMethods

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

Methods included from Member::BaseDSLMethods::ConfigurationExtension

#inherited

Methods included from Member::TypeSystemHelpers

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

Methods included from Member::Scoped

#scope_items

Methods included from Member::RelayShortcuts

#connection_type, #connection_type_class, #edge_type, #edge_type_class

Methods included from Member::HasPath

#path

Methods included from Member::HasAstNode

#ast_node

Methods included from Member::HasDirectives

#directive, #directives, #remove_directive

Class Method Details

.coerce_input(val, ctx) ⇒ Object


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

def coerce_input(val, ctx)
  val
end

.coerce_result(val, ctx) ⇒ Object


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

def coerce_result(val, ctx)
  val
end

.default_scalar(is_default = nil) ⇒ Object


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

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

.default_scalar?Boolean

Returns:


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

def default_scalar?
  @default_scalar ||= false
end

.kindObject


16
17
18
# File 'lib/graphql/schema/scalar.rb', line 16

def kind
  GraphQL::TypeKinds::SCALAR
end

.specified_by_url(new_url = nil) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/graphql/schema/scalar.rb', line 20

def specified_by_url(new_url = nil)
  if new_url
    @specified_by_url = new_url
  elsif defined?(@specified_by_url)
    @specified_by_url
  elsif superclass.respond_to?(:specified_by_url)
    superclass.specified_by_url
  else
    nil
  end
end

.validate_non_null_input(value, ctx, max_errors: nil) ⇒ Object


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

def validate_non_null_input(value, ctx, max_errors: nil)
  coerced_result = begin
    coerce_input(value, ctx)
  rescue GraphQL::CoercionError => err
    err
  rescue StandardError => err
    ctx.query.handle_or_reraise(err)
  end

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