Class: GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTypedError

Inherits:
Error
  • Object
show all
Defined in:
lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb

Constant Summary collapse

VIOLATIONS =
{
  :INVALID_TYPE         => "defaultValueInvalidType",
  :INVALID_ON_NON_NULL  => "defaultValueInvalidOnNonNullVariable",
}

Instance Attribute Summary collapse

Attributes inherited from Error

#message, #path

Instance Method Summary collapse

Constructor Details

#initialize(message, path: nil, nodes: [], name:, type: nil, error_type:) ⇒ VariableDefaultValuesAreCorrectlyTypedError

Returns a new instance of VariableDefaultValuesAreCorrectlyTypedError.


14
15
16
17
18
19
20
# File 'lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb', line 14

def initialize(message, path: nil, nodes: [], name:, type: nil, error_type:)
  super(message, path: path, nodes: nodes)
  @variable_name = name
  @type_name = type
  raise("Unexpected error type: #{error_type}") if !VIOLATIONS.values.include?(error_type)
  @violation = error_type
end

Instance Attribute Details

#type_nameObject (readonly)

Returns the value of attribute type_name


6
7
8
# File 'lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb', line 6

def type_name
  @type_name
end

#variable_nameObject (readonly)

Returns the value of attribute variable_name


5
6
7
# File 'lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb', line 5

def variable_name
  @variable_name
end

#violationObject (readonly)

Returns the value of attribute violation


7
8
9
# File 'lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb', line 7

def violation
  @violation
end

Instance Method Details

#codeObject


34
35
36
# File 'lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb', line 34

def code
  @violation
end

#to_hObject

A hash representation of this Message


23
24
25
26
27
28
29
30
31
32
# File 'lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb', line 23

def to_h
  extensions = {
    "code" => code,
    "variableName" => variable_name
  }.tap { |h| h["typeName"] = type_name unless type_name.nil? }

  super.merge({
    "extensions" => extensions
  })
end