graphql 1.13.15 → 1.13.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/query/input_validation_result.rb +9 -0
- data/lib/graphql/query/variable_validation_error.rb +2 -2
- data/lib/graphql/query/variables.rb +30 -3
- data/lib/graphql/schema/enum.rb +1 -2
- data/lib/graphql/schema/input_object.rb +1 -2
- data/lib/graphql/schema/list.rb +18 -3
- data/lib/graphql/schema/member/validates_input.rb +2 -2
- data/lib/graphql/schema/non_null.rb +2 -2
- data/lib/graphql/schema/scalar.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c562e63d8324130b431892094e4a85a45f62187ae41a08fa095f854283950c28
|
4
|
+
data.tar.gz: c38c9220f5878fe45738d0e0d9c23062c1d7c9a1b744c58d7b5b169819adabed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2597fa87c4b752878e60b6d4c809385a67e3d4192fac54fc23a97e92ba1b580531364270409f3aefb048f26fd79a764cf4c54278f85f85cb5b76b363072926f1
|
7
|
+
data.tar.gz: f40d8e5aefbdc97884e0e104bbb52bb599e3aa9f690e540b0d99f00d4dc70ed07b56b08c6a1a4ed06e0b275c1b1589242413b131f80185e908d9bddd94b3106c
|
@@ -4,6 +4,12 @@ module GraphQL
|
|
4
4
|
class InputValidationResult
|
5
5
|
attr_accessor :problems
|
6
6
|
|
7
|
+
def self.from_problem(explanation, path = nil, extensions: nil, message: nil)
|
8
|
+
result = self.new
|
9
|
+
result.add_problem(explanation, path, extensions: extensions, message: message)
|
10
|
+
result
|
11
|
+
end
|
12
|
+
|
7
13
|
def initialize(valid: true, problems: nil)
|
8
14
|
@valid = valid
|
9
15
|
@problems = problems
|
@@ -38,6 +44,9 @@ module GraphQL
|
|
38
44
|
# It could have been explicitly set on inner_result (if it had no problems)
|
39
45
|
@valid = false
|
40
46
|
end
|
47
|
+
|
48
|
+
VALID = self.new
|
49
|
+
VALID.freeze
|
41
50
|
end
|
42
51
|
end
|
43
52
|
end
|
@@ -4,11 +4,11 @@ module GraphQL
|
|
4
4
|
class VariableValidationError < GraphQL::ExecutionError
|
5
5
|
attr_accessor :value, :validation_result
|
6
6
|
|
7
|
-
def initialize(variable_ast, type, value, validation_result)
|
7
|
+
def initialize(variable_ast, type, value, validation_result, msg: nil)
|
8
8
|
@value = value
|
9
9
|
@validation_result = validation_result
|
10
10
|
|
11
|
-
msg
|
11
|
+
msg ||= "Variable $#{variable_ast.name} of type #{type.to_type_signature} was provided invalid value"
|
12
12
|
|
13
13
|
if problem_fields.any?
|
14
14
|
msg += " for #{problem_fields.join(", ")}"
|
@@ -17,6 +17,10 @@ module GraphQL
|
|
17
17
|
@provided_variables = GraphQL::Argument.deep_stringify(provided_variables)
|
18
18
|
@errors = []
|
19
19
|
@storage = ast_variables.each_with_object({}) do |ast_variable, memo|
|
20
|
+
if schema.validate_max_errors && schema.validate_max_errors <= @errors.count
|
21
|
+
add_max_errors_reached_message
|
22
|
+
break
|
23
|
+
end
|
20
24
|
# Find the right value for this variable:
|
21
25
|
# - First, use the value provided at runtime
|
22
26
|
# - Then, fall back to the default value from the query string
|
@@ -29,8 +33,9 @@ module GraphQL
|
|
29
33
|
default_value = ast_variable.default_value
|
30
34
|
provided_value = @provided_variables[variable_name]
|
31
35
|
value_was_provided = @provided_variables.key?(variable_name)
|
36
|
+
max_errors = schema.validate_max_errors - @errors.count if schema.validate_max_errors
|
32
37
|
begin
|
33
|
-
validation_result = variable_type.validate_input(provided_value, ctx)
|
38
|
+
validation_result = variable_type.validate_input(provided_value, ctx, max_errors: max_errors)
|
34
39
|
if validation_result.valid?
|
35
40
|
if value_was_provided
|
36
41
|
# Add the variable if a value was provided
|
@@ -61,8 +66,7 @@ module GraphQL
|
|
61
66
|
# like InputValidationResults generated by validate_non_null_input but unfortunately we don't
|
62
67
|
# have this information available in the coerce_input call chain. Note this path is the path
|
63
68
|
# that appears under errors.extensions.problems.path and NOT the result path under errors.path.
|
64
|
-
validation_result = GraphQL::Query::InputValidationResult.
|
65
|
-
validation_result.add_problem(ex.message)
|
69
|
+
validation_result = GraphQL::Query::InputValidationResult.from_problem(ex.message)
|
66
70
|
end
|
67
71
|
|
68
72
|
if !validation_result.valid?
|
@@ -73,6 +77,29 @@ module GraphQL
|
|
73
77
|
end
|
74
78
|
|
75
79
|
def_delegators :@storage, :length, :key?, :[], :fetch, :to_h
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def deep_stringify(val)
|
84
|
+
case val
|
85
|
+
when Array
|
86
|
+
val.map { |v| deep_stringify(v) }
|
87
|
+
when Hash
|
88
|
+
new_val = {}
|
89
|
+
val.each do |k, v|
|
90
|
+
new_val[k.to_s] = deep_stringify(v)
|
91
|
+
end
|
92
|
+
new_val
|
93
|
+
else
|
94
|
+
val
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def add_max_errors_reached_message
|
99
|
+
message = "Too many errors processing variables, max validation error limit reached. Execution aborted"
|
100
|
+
validation_result = GraphQL::Query::InputValidationResult.from_problem(message)
|
101
|
+
errors << GraphQL::Query::VariableValidationError.new(nil, nil, nil, validation_result, msg: message)
|
102
|
+
end
|
76
103
|
end
|
77
104
|
end
|
78
105
|
end
|
data/lib/graphql/schema/enum.rb
CHANGED
@@ -139,9 +139,8 @@ module GraphQL
|
|
139
139
|
GraphQL::TypeKinds::ENUM
|
140
140
|
end
|
141
141
|
|
142
|
-
def validate_non_null_input(value_name, ctx)
|
142
|
+
def validate_non_null_input(value_name, ctx, max_errors: nil)
|
143
143
|
result = GraphQL::Query::InputValidationResult.new
|
144
|
-
|
145
144
|
allowed_values = ctx.warden.enum_values(self)
|
146
145
|
matching_value = allowed_values.find { |v| v.graphql_name == value_name }
|
147
146
|
|
@@ -173,9 +173,8 @@ module GraphQL
|
|
173
173
|
# @api private
|
174
174
|
INVALID_OBJECT_MESSAGE = "Expected %{object} to be a key-value object responding to `to_h` or `to_unsafe_h`."
|
175
175
|
|
176
|
-
def validate_non_null_input(input, ctx)
|
176
|
+
def validate_non_null_input(input, ctx, max_errors: nil)
|
177
177
|
result = GraphQL::Query::InputValidationResult.new
|
178
|
-
|
179
178
|
warden = ctx.warden
|
180
179
|
|
181
180
|
if input.is_a?(Array)
|
data/lib/graphql/schema/list.rb
CHANGED
@@ -51,15 +51,24 @@ module GraphQL
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def validate_non_null_input(value, ctx)
|
54
|
+
def validate_non_null_input(value, ctx, max_errors: nil)
|
55
55
|
result = GraphQL::Query::InputValidationResult.new
|
56
56
|
ensure_array(value).each_with_index do |item, index|
|
57
57
|
item_result = of_type.validate_input(item, ctx)
|
58
|
-
|
58
|
+
unless item_result.valid?
|
59
|
+
if max_errors
|
60
|
+
if max_errors == 0
|
61
|
+
add_max_errros_reached_message(result)
|
62
|
+
break
|
63
|
+
end
|
64
|
+
|
65
|
+
max_errors -= 1
|
66
|
+
end
|
67
|
+
|
59
68
|
result.merge_result!(index, item_result)
|
60
69
|
end
|
61
70
|
end
|
62
|
-
result
|
71
|
+
result.valid? ? nil : result
|
63
72
|
end
|
64
73
|
|
65
74
|
private
|
@@ -72,6 +81,12 @@ module GraphQL
|
|
72
81
|
[value]
|
73
82
|
end
|
74
83
|
end
|
84
|
+
|
85
|
+
def add_max_errros_reached_message(result)
|
86
|
+
message = "Too many errors processing list variable, max validation error limit reached. Execution aborted"
|
87
|
+
item_result = GraphQL::Query::InputValidationResult.from_problem(message)
|
88
|
+
result.merge_result!(nil, item_result)
|
89
|
+
end
|
75
90
|
end
|
76
91
|
end
|
77
92
|
end
|
@@ -8,11 +8,11 @@ module GraphQL
|
|
8
8
|
validate_input(val, ctx).valid?
|
9
9
|
end
|
10
10
|
|
11
|
-
def validate_input(val, ctx)
|
11
|
+
def validate_input(val, ctx, max_errors: nil)
|
12
12
|
if val.nil?
|
13
13
|
GraphQL::Query::InputValidationResult.new
|
14
14
|
else
|
15
|
-
validate_non_null_input(val, ctx)
|
15
|
+
validate_non_null_input(val, ctx, max_errors: max_errors) || Query::InputValidationResult::VALID
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -37,13 +37,13 @@ module GraphQL
|
|
37
37
|
"#<#{self.class.name} @of_type=#{@of_type.inspect}>"
|
38
38
|
end
|
39
39
|
|
40
|
-
def validate_input(value, ctx)
|
40
|
+
def validate_input(value, ctx, max_errors: nil)
|
41
41
|
if value.nil?
|
42
42
|
result = GraphQL::Query::InputValidationResult.new
|
43
43
|
result.add_problem("Expected value to not be null")
|
44
44
|
result
|
45
45
|
else
|
46
|
-
of_type.validate_input(value, ctx)
|
46
|
+
of_type.validate_input(value, ctx, max_errors: max_errors)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -55,7 +55,7 @@ module GraphQL
|
|
55
55
|
@default_scalar ||= false
|
56
56
|
end
|
57
57
|
|
58
|
-
def validate_non_null_input(value, ctx)
|
58
|
+
def validate_non_null_input(value, ctx, max_errors: nil)
|
59
59
|
result = Query::InputValidationResult.new
|
60
60
|
coerced_result = begin
|
61
61
|
ctx.query.with_error_handling do
|
data/lib/graphql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.13.
|
4
|
+
version: 1.13.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|