class GraphQL::Query::VariableValidationError

Attributes

validation_result[RW]
value[RW]

Public Class Methods

new(variable_ast, type, value, validation_result, msg: nil) click to toggle source
Calls superclass method GraphQL::ExecutionError::new
# File lib/graphql/query/variable_validation_error.rb, line 7
def initialize(variable_ast, type, value, validation_result, msg: nil)
  @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

Public Instance Methods

to_h() click to toggle source
Calls superclass method GraphQL::ExecutionError#to_h
# 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

Private Instance Methods

problem_fields() click to toggle source
# File lib/graphql/query/variable_validation_error.rb, line 36
def problem_fields
  @problem_fields ||= @validation_result
    .problems
    .reject { |problem| problem["path"].empty? }
    .map { |problem| "#{problem['path'].join('.')} (#{problem['explanation']})" }
end