Exception: GraphQL::Query::VariableValidationError

Inherits:
ExecutionError show all
Defined in:
lib/graphql/query/variable_validation_error.rb

Instance Attribute Summary collapse

Attributes inherited from ExecutionError

#ast_node, #extensions, #options, #path

Instance Method Summary collapse

Constructor Details

#initialize(variable_ast, type, value, validation_result) ⇒ VariableValidationError

Returns a new instance of VariableValidationError.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/graphql/query/variable_validation_error.rb', line 7

def initialize(variable_ast, type, value, validation_result)
  @value = value
  @validation_result = validation_result

  msg = "Variable $#{variable_ast.name} of type #{type.to_type_signature} was provided invalid value"

  if problem_fields.any?
    msg += " for #{problem_fields.join(", ")}"
  end

  super(msg)
  self.ast_node = variable_ast
end

Instance Attribute Details

#validation_resultObject

Returns the value of attribute validation_result.



5
6
7
# File 'lib/graphql/query/variable_validation_error.rb', line 5

def validation_result
  @validation_result
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/graphql/query/variable_validation_error.rb', line 5

def value
  @value
end

Instance Method Details

#to_hObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/graphql/query/variable_validation_error.rb', line 21

def to_h
  # It is possible there are other extension items in this error, so handle
  # a one level deep merge explicitly. However beyond that only show the
  # latest value and problems.
  super.merge({ "extensions" => { "value" => value, "problems" => validation_result.problems }}) do |key, oldValue, newValue|
    if oldValue.respond_to?(:merge)
      oldValue.merge(newValue)
    else
      newValue
    end
  end
end