Class: GraphQL::Query::InputValidationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/query/input_validation_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(valid: true, problems: nil) ⇒ InputValidationResult

Returns a new instance of InputValidationResult.


7
8
9
10
# File 'lib/graphql/query/input_validation_result.rb', line 7

def initialize(valid: true, problems: nil)
  @valid = valid
  @problems = problems
end

Instance Attribute Details

#problemsObject

Returns the value of attribute problems


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

def problems
  @problems
end

Instance Method Details

#add_problem(explanation, path = nil, extensions: nil, message: nil) ⇒ Object


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

def add_problem(explanation, path = nil, extensions: nil, message: nil)
  @problems ||= []
  @valid = false
  problem = { "path" => path || [], "explanation" => explanation }
  if extensions
    problem["extensions"] = extensions
  end
  if message
    problem["message"] = message
  end
  @problems.push(problem)
end

#merge_result!(path, inner_result) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/graphql/query/input_validation_result.rb', line 29

def merge_result!(path, inner_result)
  return if inner_result.valid?

  if inner_result.problems
    inner_result.problems.each do |p|
      item_path = [path, *p["path"]]
      add_problem(p["explanation"], item_path, message: p["message"], extensions: p["extensions"])
    end
  end
  # It could have been explicitly set on inner_result (if it had no problems)
  @valid = false
end

#valid?Boolean

Returns:

  • (Boolean)

12
13
14
# File 'lib/graphql/query/input_validation_result.rb', line 12

def valid?
  @valid
end