Class: GraphQL::Query::InputValidationResult
- Inherits:
-
Object
- Object
- GraphQL::Query::InputValidationResult
- Defined in:
- lib/graphql/query/input_validation_result.rb
Constant Summary collapse
- VALID =
self.new
Instance Attribute Summary collapse
-
#coerced_value ⇒ Object
Returns.
-
#problems ⇒ Object
Returns the value of attribute problems.
Class Method Summary collapse
-
.coerced(value) ⇒ Object
Build a valid result which carries the coerced Ruby value for this input.
- .from_problem(explanation, path = nil, extensions: nil, message: nil) ⇒ Object
Instance Method Summary collapse
- #add_problem(explanation, path = nil, extensions: nil, message: nil) ⇒ Object
-
#coerced_value? ⇒ Boolean
Returns.
-
#initialize(valid: true, problems: nil) ⇒ InputValidationResult
constructor
A new instance of InputValidationResult.
- #merge_result!(path, inner_result) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(valid: true, problems: nil) ⇒ InputValidationResult
Returns a new instance of InputValidationResult.
36 37 38 39 40 41 |
# File 'lib/graphql/query/input_validation_result.rb', line 36 def initialize(valid: true, problems: nil) @valid = valid @problems = problems @coerced_value = nil @has_coerced_value = false end |
Instance Attribute Details
#coerced_value ⇒ Object
Returns
Object— The coerced value, if one was given with coerced_value=
46 47 48 |
# File 'lib/graphql/query/input_validation_result.rb', line 46 def coerced_value @coerced_value end |
#problems ⇒ Object
Returns the value of attribute problems.
7 8 9 |
# File 'lib/graphql/query/input_validation_result.rb', line 7 def problems @problems end |
Class Method Details
.coerced(value) ⇒ Object
Build a valid result which carries the coerced Ruby value for this input.
Return this from validate_non_null_input to give GraphQL-Ruby the coerced value,
so that it doesn't call coerce_input again. value may be nil.
Parameters
value(Object) — The coerced Ruby value
Returns
GraphQL::Query::InputValidationResult
:call-seq:
coerced(Object value) -> GraphQL::Query::InputValidationResult
30 31 32 33 34 |
# File 'lib/graphql/query/input_validation_result.rb', line 30 def self.coerced(value) result = self.new result.coerced_value = value result end |
.from_problem(explanation, path = nil, extensions: nil, message: nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/graphql/query/input_validation_result.rb', line 9 def self.from_problem(explanation, path = nil, extensions: nil, message: nil) result = self.new result.add_problem(explanation, path, extensions: extensions, message: ) result end |
Instance Method Details
#add_problem(explanation, path = nil, extensions: nil, message: nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/graphql/query/input_validation_result.rb', line 67 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 problem["message"] = end @problems.push(problem) end |
#coerced_value? ⇒ Boolean
Returns
Boolean— true if a coerced value was given with coerced_value=
:call-seq:
coerced_value?() -> bool
59 60 61 |
# File 'lib/graphql/query/input_validation_result.rb', line 59 def coerced_value? @has_coerced_value end |
#merge_result!(path, inner_result) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/graphql/query/input_validation_result.rb', line 80 def merge_result!(path, inner_result) return if inner_result.nil? || 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
63 64 65 |
# File 'lib/graphql/query/input_validation_result.rb', line 63 def valid? @valid end |