graphql 2.0.23 → 2.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/dataloader/source.rb +3 -4
- data/lib/graphql/execution/interpreter/runtime.rb +13 -19
- data/lib/graphql/introspection/entry_points.rb +1 -1
- data/lib/graphql/query/validation_pipeline.rb +2 -1
- data/lib/graphql/query.rb +16 -1
- data/lib/graphql/schema/addition.rb +32 -12
- data/lib/graphql/schema/field.rb +1 -1
- data/lib/graphql/schema/introspection_system.rb +1 -1
- data/lib/graphql/schema/member/build_type.rb +10 -2
- data/lib/graphql/schema/object.rb +5 -0
- data/lib/graphql/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c97d63232efb5f7ecdaef0f8102a73ceaa4a4b0a3b06c7ab1f613735efafa59
|
4
|
+
data.tar.gz: aff3df56a3db15d97f457e92fffab33f29440fed5ca84b0515794ad051e5631e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cf33d0ed4df848c57e459f9ee023b0a6b2814d14ef09d7c304120a595cd62e65f25b05b3f16448c89cfb9479d06e550611c42fa76b3fb92a677c788f31f713e
|
7
|
+
data.tar.gz: 28b8d5e3fb2d6cc0bc3ebbdaf6f6d53dc16b0225bcafcc0fe72d4956afb9ff0fdb1ca929093ad466951dc28a30d893e643c8fb68bff69df374e41e1c43e2980b
|
@@ -39,7 +39,7 @@ module GraphQL
|
|
39
39
|
result_for(key)
|
40
40
|
else
|
41
41
|
@pending_keys << key
|
42
|
-
sync
|
42
|
+
sync([key])
|
43
43
|
result_for(key)
|
44
44
|
end
|
45
45
|
end
|
@@ -50,7 +50,7 @@ module GraphQL
|
|
50
50
|
if keys.any? { |k| !@results.key?(k) }
|
51
51
|
pending_keys = keys.select { |k| !@results.key?(k) }
|
52
52
|
@pending_keys.concat(pending_keys)
|
53
|
-
sync
|
53
|
+
sync(pending_keys)
|
54
54
|
end
|
55
55
|
|
56
56
|
keys.map { |k| result_for(k) }
|
@@ -67,8 +67,7 @@ module GraphQL
|
|
67
67
|
# Wait for a batch, if there's anything to batch.
|
68
68
|
# Then run the batch and update the cache.
|
69
69
|
# @return [void]
|
70
|
-
def sync
|
71
|
-
pending_keys = @pending_keys.dup
|
70
|
+
def sync(pending_keys)
|
72
71
|
@dataloader.yield
|
73
72
|
iterations = 0
|
74
73
|
while pending_keys.any? { |k| !@results.key?(k) }
|
@@ -247,15 +247,15 @@ module GraphQL
|
|
247
247
|
st = get_current_runtime_state
|
248
248
|
st.current_object = query.root_value
|
249
249
|
st.current_result = @response
|
250
|
-
|
251
|
-
|
250
|
+
runtime_object = root_type.wrap(query.root_value, context)
|
251
|
+
runtime_object = schema.sync_lazy(runtime_object)
|
252
252
|
|
253
|
-
if
|
253
|
+
if runtime_object.nil?
|
254
254
|
# Root .authorized? returned false.
|
255
255
|
@response = nil
|
256
256
|
else
|
257
|
-
call_method_on_directives(:resolve,
|
258
|
-
gathered_selections = gather_selections(
|
257
|
+
call_method_on_directives(:resolve, runtime_object, root_operation.directives) do # execute query level directives
|
258
|
+
gathered_selections = gather_selections(runtime_object, root_type, root_operation.selections)
|
259
259
|
# This is kind of a hack -- `gathered_selections` is an Array if any of the selections
|
260
260
|
# require isolation during execution (because of runtime directives). In that case,
|
261
261
|
# make a new, isolated result hash for writing the result into. (That isolated response
|
@@ -280,9 +280,9 @@ module GraphQL
|
|
280
280
|
if (directives = selections[:graphql_directives])
|
281
281
|
selections.delete(:graphql_directives)
|
282
282
|
end
|
283
|
-
call_method_on_directives(:resolve,
|
283
|
+
call_method_on_directives(:resolve, runtime_object, directives) do
|
284
284
|
evaluate_selections(
|
285
|
-
|
285
|
+
runtime_object,
|
286
286
|
root_type,
|
287
287
|
root_op_type == "mutation",
|
288
288
|
selections,
|
@@ -438,10 +438,8 @@ module GraphQL
|
|
438
438
|
st.current_result = selections_result
|
439
439
|
st.current_result_name = result_name
|
440
440
|
|
441
|
-
object = owner_object
|
442
|
-
|
443
441
|
if is_introspection
|
444
|
-
|
442
|
+
owner_object = field_defn.owner.wrap(owner_object, context)
|
445
443
|
end
|
446
444
|
|
447
445
|
total_args_count = field_defn.arguments(context).size
|
@@ -449,14 +447,14 @@ module GraphQL
|
|
449
447
|
resolved_arguments = GraphQL::Execution::Interpreter::Arguments::EMPTY
|
450
448
|
if field_defn.extras.size == 0
|
451
449
|
evaluate_selection_with_resolved_keyword_args(
|
452
|
-
NO_ARGS, resolved_arguments, field_defn, ast_node, field_ast_nodes, owner_type,
|
450
|
+
NO_ARGS, resolved_arguments, field_defn, ast_node, field_ast_nodes, owner_type, owner_object, is_eager_field, result_name, selections_result, parent_object, return_type, return_type_non_null
|
453
451
|
)
|
454
452
|
else
|
455
|
-
evaluate_selection_with_args(resolved_arguments, field_defn, ast_node, field_ast_nodes, owner_type,
|
453
|
+
evaluate_selection_with_args(resolved_arguments, field_defn, ast_node, field_ast_nodes, owner_type, owner_object, is_eager_field, result_name, selections_result, parent_object, return_type, return_type_non_null)
|
456
454
|
end
|
457
455
|
else
|
458
|
-
@query.arguments_cache.dataload_for(ast_node, field_defn,
|
459
|
-
evaluate_selection_with_args(resolved_arguments, field_defn, ast_node, field_ast_nodes, owner_type,
|
456
|
+
@query.arguments_cache.dataload_for(ast_node, field_defn, owner_object) do |resolved_arguments|
|
457
|
+
evaluate_selection_with_args(resolved_arguments, field_defn, ast_node, field_ast_nodes, owner_type, owner_object, is_eager_field, result_name, selections_result, parent_object, return_type, return_type_non_null)
|
460
458
|
end
|
461
459
|
end
|
462
460
|
end
|
@@ -774,7 +772,7 @@ module GraphQL
|
|
774
772
|
end
|
775
773
|
when "OBJECT"
|
776
774
|
object_proxy = begin
|
777
|
-
|
775
|
+
current_type.wrap(value, context)
|
778
776
|
rescue GraphQL::ExecutionError => err
|
779
777
|
err
|
780
778
|
end
|
@@ -1047,10 +1045,6 @@ module GraphQL
|
|
1047
1045
|
end
|
1048
1046
|
end
|
1049
1047
|
|
1050
|
-
def authorized_new(type, value, context)
|
1051
|
-
type.authorized_new(value, context)
|
1052
|
-
end
|
1053
|
-
|
1054
1048
|
def lazy?(object)
|
1055
1049
|
obj_class = object.class
|
1056
1050
|
is_lazy = @lazy_cache[obj_class]
|
@@ -11,7 +11,7 @@ module GraphQL
|
|
11
11
|
# Apply wrapping manually since this field isn't wrapped by instrumentation
|
12
12
|
schema = @context.query.schema
|
13
13
|
schema_type = schema.introspection_system.types["__Schema"]
|
14
|
-
schema_type.
|
14
|
+
schema_type.wrap(schema, @context)
|
15
15
|
end
|
16
16
|
|
17
17
|
def __type(name:)
|
@@ -68,7 +68,8 @@ module GraphQL
|
|
68
68
|
elsif @operation_name_error
|
69
69
|
@validation_errors << @operation_name_error
|
70
70
|
else
|
71
|
-
|
71
|
+
validator = @query.static_validator || @schema.static_validator
|
72
|
+
validation_result = validator.validate(@query, validate: @query.validate, timeout: @schema.validate_timeout, max_errors: @schema.validate_max_errors)
|
72
73
|
@validation_errors.concat(validation_result[:errors])
|
73
74
|
|
74
75
|
if @validation_errors.empty?
|
data/lib/graphql/query.rb
CHANGED
@@ -45,6 +45,20 @@ module GraphQL
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
# @return [GraphQL::StaticValidation::Validator] if present, the query will validate with these rules.
|
49
|
+
attr_reader :static_validator
|
50
|
+
|
51
|
+
# @param new_validate [GraphQL::StaticValidation::Validator] if present, the query will validate with these rules. This can't be reasssigned after validation.
|
52
|
+
def static_validator=(new_validator)
|
53
|
+
if defined?(@validation_pipeline) && @validation_pipeline && @validation_pipeline.has_validated?
|
54
|
+
raise ArgumentError, "Can't reassign Query#static_validator= after validation has run, remove this assignment."
|
55
|
+
elsif !new_validator.is_a?(GraphQL::StaticValidation::Validator)
|
56
|
+
raise ArgumentError, "Expected a `GraphQL::StaticValidation::Validator` instance."
|
57
|
+
else
|
58
|
+
@static_validator = new_validator
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
48
62
|
attr_writer :query_string
|
49
63
|
|
50
64
|
# @return [GraphQL::Language::Nodes::Document]
|
@@ -83,7 +97,7 @@ module GraphQL
|
|
83
97
|
# @param max_complexity [Numeric] the maximum field complexity for this query (falls back to schema-level value)
|
84
98
|
# @param except [<#call(schema_member, context)>] If provided, objects will be hidden from the schema when `.call(schema_member, context)` returns truthy
|
85
99
|
# @param only [<#call(schema_member, context)>] If provided, objects will be hidden from the schema when `.call(schema_member, context)` returns false
|
86
|
-
def initialize(schema, query_string = nil, query: nil, document: nil, context: nil, variables: nil, validate: true, subscription_topic: nil, operation_name: nil, root_value: nil, max_depth: schema.max_depth, max_complexity: schema.max_complexity, except: nil, only: nil, warden: nil)
|
100
|
+
def initialize(schema, query_string = nil, query: nil, document: nil, context: nil, variables: nil, validate: true, static_validator: nil, subscription_topic: nil, operation_name: nil, root_value: nil, max_depth: schema.max_depth, max_complexity: schema.max_complexity, except: nil, only: nil, warden: nil)
|
87
101
|
# Even if `variables: nil` is passed, use an empty hash for simpler logic
|
88
102
|
variables ||= {}
|
89
103
|
@schema = schema
|
@@ -97,6 +111,7 @@ module GraphQL
|
|
97
111
|
@fragments = nil
|
98
112
|
@operations = nil
|
99
113
|
@validate = validate
|
114
|
+
self.static_validator = static_validator if static_validator
|
100
115
|
context_tracers = (context ? context.fetch(:tracers, []) : [])
|
101
116
|
@tracers = schema.tracers + context_tracers
|
102
117
|
|
@@ -40,14 +40,21 @@ module GraphQL
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def add_directives_from(owner)
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
if (dir_instances = owner.directives).any?
|
44
|
+
dirs = dir_instances.map(&:class)
|
45
|
+
@directives.merge(dirs)
|
46
|
+
add_type_and_traverse(dirs)
|
47
|
+
end
|
46
48
|
end
|
47
49
|
|
48
50
|
def add_type_and_traverse(new_types)
|
49
51
|
late_types = []
|
50
|
-
|
52
|
+
path = []
|
53
|
+
new_types.each do |t|
|
54
|
+
path.push(t.graphql_name)
|
55
|
+
add_type(t, owner: nil, late_types: late_types, path: path)
|
56
|
+
path.pop
|
57
|
+
end
|
51
58
|
missed_late_types = 0
|
52
59
|
while (late_type_vals = late_types.shift)
|
53
60
|
type_owner, lt = late_type_vals
|
@@ -158,7 +165,9 @@ module GraphQL
|
|
158
165
|
type.all_argument_definitions.each do |arg|
|
159
166
|
arg_type = arg.type.unwrap
|
160
167
|
references_to(arg_type, from: arg)
|
161
|
-
|
168
|
+
path.push(arg.graphql_name)
|
169
|
+
add_type(arg_type, owner: arg, late_types: late_types, path: path)
|
170
|
+
path.pop
|
162
171
|
if arg.default_value?
|
163
172
|
@arguments_with_default_values << arg
|
164
173
|
end
|
@@ -179,18 +188,21 @@ module GraphQL
|
|
179
188
|
name = field.graphql_name
|
180
189
|
field_type = field.type.unwrap
|
181
190
|
references_to(field_type, from: field)
|
182
|
-
|
183
|
-
add_type(field_type, owner: field, late_types: late_types, path:
|
191
|
+
path.push(name)
|
192
|
+
add_type(field_type, owner: field, late_types: late_types, path: path)
|
184
193
|
add_directives_from(field)
|
185
194
|
field.all_argument_definitions.each do |arg|
|
186
195
|
add_directives_from(arg)
|
187
196
|
arg_type = arg.type.unwrap
|
188
197
|
references_to(arg_type, from: arg)
|
189
|
-
|
198
|
+
path.push(arg.graphql_name)
|
199
|
+
add_type(arg_type, owner: arg, late_types: late_types, path: path)
|
200
|
+
path.pop
|
190
201
|
if arg.default_value?
|
191
202
|
@arguments_with_default_values << arg
|
192
203
|
end
|
193
204
|
end
|
205
|
+
path.pop
|
194
206
|
end
|
195
207
|
end
|
196
208
|
if type.kind.input_object?
|
@@ -198,7 +210,9 @@ module GraphQL
|
|
198
210
|
add_directives_from(arg)
|
199
211
|
arg_type = arg.type.unwrap
|
200
212
|
references_to(arg_type, from: arg)
|
201
|
-
|
213
|
+
path.push(arg.graphql_name)
|
214
|
+
add_type(arg_type, owner: arg, late_types: late_types, path: path)
|
215
|
+
path.pop
|
202
216
|
if arg.default_value?
|
203
217
|
@arguments_with_default_values << arg
|
204
218
|
end
|
@@ -206,14 +220,18 @@ module GraphQL
|
|
206
220
|
end
|
207
221
|
if type.kind.union?
|
208
222
|
@possible_types[type.graphql_name] = type.all_possible_types
|
223
|
+
path.push("possible_types")
|
209
224
|
type.all_possible_types.each do |t|
|
210
|
-
add_type(t, owner: type, late_types: late_types, path: path
|
225
|
+
add_type(t, owner: type, late_types: late_types, path: path)
|
211
226
|
end
|
227
|
+
path.pop
|
212
228
|
end
|
213
229
|
if type.kind.interface?
|
230
|
+
path.push("orphan_types")
|
214
231
|
type.orphan_types.each do |t|
|
215
|
-
add_type(t, owner: type, late_types: late_types, path: path
|
232
|
+
add_type(t, owner: type, late_types: late_types, path: path)
|
216
233
|
end
|
234
|
+
path.pop
|
217
235
|
end
|
218
236
|
if type.kind.object?
|
219
237
|
possible_types_for_this_name = @possible_types[type.graphql_name] ||= []
|
@@ -221,6 +239,7 @@ module GraphQL
|
|
221
239
|
end
|
222
240
|
|
223
241
|
if type.kind.object? || type.kind.interface?
|
242
|
+
path.push("implements")
|
224
243
|
type.interface_type_memberships.each do |interface_type_membership|
|
225
244
|
case interface_type_membership
|
226
245
|
when Schema::TypeMembership
|
@@ -235,8 +254,9 @@ module GraphQL
|
|
235
254
|
else
|
236
255
|
raise ArgumentError, "Invariant: unexpected type membership for #{type.graphql_name}: #{interface_type_membership.class} (#{interface_type_membership.inspect})"
|
237
256
|
end
|
238
|
-
add_type(interface_type, owner: type, late_types: late_types, path: path
|
257
|
+
add_type(interface_type, owner: type, late_types: late_types, path: path)
|
239
258
|
end
|
259
|
+
path.pop
|
240
260
|
end
|
241
261
|
end
|
242
262
|
end
|
data/lib/graphql/schema/field.rb
CHANGED
@@ -155,7 +155,7 @@ module GraphQL
|
|
155
155
|
if obj.is_a?(GraphQL::Schema::Object)
|
156
156
|
obj = obj.object
|
157
157
|
end
|
158
|
-
wrapped_object = @object_class.
|
158
|
+
wrapped_object = @object_class.wrap(obj, query_ctx)
|
159
159
|
@inner_resolve.call(wrapped_object, args, ctx)
|
160
160
|
end
|
161
161
|
end
|
@@ -109,7 +109,14 @@ module GraphQL
|
|
109
109
|
to_type_name(something.name)
|
110
110
|
end
|
111
111
|
when String
|
112
|
-
something.
|
112
|
+
if something.include?("]") ||
|
113
|
+
something.include?("[") ||
|
114
|
+
something.include?("!") ||
|
115
|
+
something.include?("::")
|
116
|
+
something.gsub(/\]\[\!/, "").split("::").last
|
117
|
+
else
|
118
|
+
something
|
119
|
+
end
|
113
120
|
when GraphQL::Schema::NonNull, GraphQL::Schema::List
|
114
121
|
to_type_name(something.unwrap)
|
115
122
|
else
|
@@ -122,7 +129,8 @@ module GraphQL
|
|
122
129
|
return string unless string.include?("_")
|
123
130
|
camelized = string.split('_').each(&:capitalize!).join
|
124
131
|
camelized[0] = camelized[0].downcase
|
125
|
-
if
|
132
|
+
if string.start_with?("_")
|
133
|
+
match_data = string.match(/\A(_+)/)
|
126
134
|
camelized = "#{match_data[0]}#{camelized}"
|
127
135
|
end
|
128
136
|
camelized
|
@@ -30,6 +30,11 @@ module GraphQL
|
|
30
30
|
# @see authorized_new to make instances
|
31
31
|
protected :new
|
32
32
|
|
33
|
+
# This is called by the runtime to return an object to call methods on.
|
34
|
+
def wrap(object, context)
|
35
|
+
authorized_new(object, context)
|
36
|
+
end
|
37
|
+
|
33
38
|
# Make a new instance of this type _if_ the auth check passes,
|
34
39
|
# otherwise, raise an error.
|
35
40
|
#
|
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: 2.0.
|
4
|
+
version: 2.0.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -623,7 +623,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
623
623
|
- !ruby/object:Gem::Version
|
624
624
|
version: '0'
|
625
625
|
requirements: []
|
626
|
-
rubygems_version: 3.
|
626
|
+
rubygems_version: 3.2.33
|
627
627
|
signing_key:
|
628
628
|
specification_version: 4
|
629
629
|
summary: A GraphQL language and runtime for Ruby
|