graphql 1.11.0 → 1.11.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/core.rb +8 -0
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- data/lib/generators/graphql/templates/base_enum.erb +2 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +2 -0
- data/lib/generators/graphql/templates/base_interface.erb +2 -0
- data/lib/generators/graphql/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/templates/base_object.erb +2 -0
- data/lib/generators/graphql/templates/base_scalar.erb +2 -0
- data/lib/generators/graphql/templates/base_union.erb +2 -0
- data/lib/generators/graphql/templates/enum.erb +2 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +13 -9
- data/lib/generators/graphql/templates/interface.erb +2 -0
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +2 -0
- data/lib/generators/graphql/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/templates/object.erb +2 -0
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/scalar.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +2 -0
- data/lib/generators/graphql/templates/union.erb +3 -1
- data/lib/graphql.rb +19 -3
- data/lib/graphql/argument.rb +3 -3
- data/lib/graphql/backtrace/tracer.rb +2 -1
- data/lib/graphql/directive.rb +4 -0
- data/lib/graphql/execution/interpreter.rb +10 -0
- data/lib/graphql/execution/interpreter/arguments.rb +1 -1
- data/lib/graphql/execution/interpreter/runtime.rb +61 -46
- data/lib/graphql/field.rb +4 -0
- data/lib/graphql/input_object_type.rb +4 -0
- data/lib/graphql/introspection.rb +96 -0
- data/lib/graphql/introspection/field_type.rb +7 -3
- data/lib/graphql/introspection/input_value_type.rb +6 -0
- data/lib/graphql/introspection/introspection_query.rb +6 -92
- data/lib/graphql/introspection/type_type.rb +7 -3
- data/lib/graphql/invalid_null_error.rb +18 -0
- data/lib/graphql/language/block_string.rb +24 -5
- data/lib/graphql/language/lexer.rb +7 -3
- data/lib/graphql/language/lexer.rl +7 -3
- data/lib/graphql/language/nodes.rb +2 -1
- data/lib/graphql/language/parser.rb +107 -103
- data/lib/graphql/language/parser.y +4 -0
- data/lib/graphql/language/sanitized_printer.rb +59 -26
- data/lib/graphql/language/visitor.rb +2 -2
- data/lib/graphql/name_validator.rb +6 -7
- data/lib/graphql/pagination/connection.rb +6 -8
- data/lib/graphql/pagination/connections.rb +14 -0
- data/lib/graphql/query.rb +2 -2
- data/lib/graphql/query/context.rb +30 -3
- data/lib/graphql/query/fingerprint.rb +2 -0
- data/lib/graphql/query/validation_pipeline.rb +3 -0
- data/lib/graphql/schema.rb +40 -31
- data/lib/graphql/schema/argument.rb +56 -5
- data/lib/graphql/schema/build_from_definition.rb +60 -35
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +3 -1
- data/lib/graphql/schema/directive/deprecated.rb +1 -1
- data/lib/graphql/schema/enum_value.rb +1 -0
- data/lib/graphql/schema/field.rb +20 -5
- data/lib/graphql/schema/field/connection_extension.rb +42 -33
- data/lib/graphql/schema/input_object.rb +21 -18
- data/lib/graphql/schema/interface.rb +1 -1
- data/lib/graphql/schema/late_bound_type.rb +2 -2
- data/lib/graphql/schema/loader.rb +20 -1
- data/lib/graphql/schema/member/build_type.rb +14 -4
- data/lib/graphql/schema/member/has_arguments.rb +19 -1
- data/lib/graphql/schema/member/has_fields.rb +15 -5
- data/lib/graphql/schema/member/type_system_helpers.rb +2 -2
- data/lib/graphql/schema/mutation.rb +4 -0
- data/lib/graphql/schema/object.rb +1 -1
- data/lib/graphql/schema/relay_classic_mutation.rb +3 -1
- data/lib/graphql/schema/resolver.rb +6 -0
- data/lib/graphql/schema/resolver/has_payload_type.rb +2 -1
- data/lib/graphql/schema/subscription.rb +2 -12
- data/lib/graphql/schema/timeout.rb +29 -15
- data/lib/graphql/schema/union.rb +29 -0
- data/lib/graphql/schema/validation.rb +8 -0
- data/lib/graphql/schema/warden.rb +8 -3
- data/lib/graphql/static_validation/literal_validator.rb +7 -7
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +2 -2
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +1 -2
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +4 -2
- data/lib/graphql/static_validation/validator.rb +7 -4
- data/lib/graphql/subscriptions.rb +32 -22
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +45 -20
- data/lib/graphql/subscriptions/serialize.rb +22 -4
- data/lib/graphql/tracing.rb +1 -0
- data/lib/graphql/tracing/appoptics_tracing.rb +10 -2
- data/lib/graphql/tracing/platform_tracing.rb +25 -15
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/types/iso_8601_date_time.rb +2 -1
- data/lib/graphql/types/relay/base_connection.rb +6 -5
- data/lib/graphql/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 003526dc3efe3c95425607d76c4beffa6777cb71458e7b5ddbc1deecfc5973df
|
4
|
+
data.tar.gz: 0aa562c5b69dd2a8294bc90540af71cc4b6e7b8f701f71b3f18a0f47dcf9594b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8563c973af0d9060ae1a90e39affb7b2b8afec3233181f4cb00277d3c754a9446c3f994b8bb9c81689a1d1db92e19f91195b8e2e14a21fec7e2c43c93fc18840
|
7
|
+
data.tar.gz: 3e61b7f17cc56bb1873e4efe5b6c5b0e8142b2ec7ea211632476411acf6112876fa554f4a12b56b538480367a4f4f174dd089cd8f24a032257974f9b4079876e
|
@@ -1,3 +1,4 @@
|
|
1
|
+
<% module_namespacing_when_supported do -%>
|
1
2
|
class GraphqlController < ApplicationController
|
2
3
|
# If accessing from outside this domain, nullify the session
|
3
4
|
# This allows for outside API access while preventing CSRF attacks,
|
@@ -5,7 +6,7 @@ class GraphqlController < ApplicationController
|
|
5
6
|
# protect_from_forgery with: :null_session
|
6
7
|
|
7
8
|
def execute
|
8
|
-
variables =
|
9
|
+
variables = prepare_variables(params[:variables])
|
9
10
|
query = params[:query]
|
10
11
|
operation_name = params[:operationName]
|
11
12
|
context = {
|
@@ -21,21 +22,23 @@ class GraphqlController < ApplicationController
|
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
|
-
# Handle form data, JSON body, or a blank value
|
25
|
-
def
|
26
|
-
case
|
25
|
+
# Handle variables in form data, JSON body, or a blank value
|
26
|
+
def prepare_variables(variables_param)
|
27
|
+
case variables_param
|
27
28
|
when String
|
28
|
-
if
|
29
|
-
|
29
|
+
if variables_param.present?
|
30
|
+
JSON.parse(variables_param) || {}
|
30
31
|
else
|
31
32
|
{}
|
32
33
|
end
|
33
|
-
when Hash
|
34
|
-
|
34
|
+
when Hash
|
35
|
+
variables_param
|
36
|
+
when ActionController::Parameters
|
37
|
+
variables_param.to_unsafe_hash # GraphQL-Ruby will validate name and type of incoming variables.
|
35
38
|
when nil
|
36
39
|
{}
|
37
40
|
else
|
38
|
-
raise ArgumentError, "Unexpected parameter: #{
|
41
|
+
raise ArgumentError, "Unexpected parameter: #{variables_param}"
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
@@ -46,3 +49,4 @@ class GraphqlController < ApplicationController
|
|
46
49
|
render json: { errors: [{ message: e.message, backtrace: e.backtrace }], data: {} }, status: 500
|
47
50
|
end
|
48
51
|
end
|
52
|
+
<% end -%>
|
@@ -1,6 +1,8 @@
|
|
1
|
+
<% module_namespacing_when_supported do -%>
|
1
2
|
module Types
|
2
3
|
class <%= type_ruby_name.split('::')[-1] %> < Types::BaseObject
|
3
4
|
<% if options.node %> implements GraphQL::Relay::Node.interface
|
4
5
|
<% end %><% normalized_fields.each do |f| %> <%= f.to_ruby %>
|
5
6
|
<% end %> end
|
6
7
|
end
|
8
|
+
<% end -%>
|
@@ -1,5 +1,7 @@
|
|
1
|
+
<% module_namespacing_when_supported do -%>
|
1
2
|
module Types
|
2
3
|
class <%= type_ruby_name.split('::')[-1] %> < Types::BaseUnion
|
3
|
-
<% if possible_types.any? %> possible_types
|
4
|
+
<% if possible_types.any? %> possible_types <%= normalized_possible_types.join(", ") %>
|
4
5
|
<% end %> end
|
5
6
|
end
|
7
|
+
<% end -%>
|
data/lib/graphql.rb
CHANGED
@@ -21,6 +21,14 @@ module GraphQL
|
|
21
21
|
class RequiredImplementationMissingError < Error
|
22
22
|
end
|
23
23
|
|
24
|
+
class << self
|
25
|
+
def default_parser
|
26
|
+
@default_parser ||= GraphQL::Language::Parser
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_writer :default_parser
|
30
|
+
end
|
31
|
+
|
24
32
|
# Turn a query string or schema definition into an AST
|
25
33
|
# @param graphql_string [String] a GraphQL query string or schema definition
|
26
34
|
# @return [GraphQL::Language::Nodes::Document]
|
@@ -61,6 +69,14 @@ module GraphQL
|
|
61
69
|
end
|
62
70
|
end
|
63
71
|
end
|
72
|
+
|
73
|
+
module StringMatchBackport
|
74
|
+
refine String do
|
75
|
+
def match?(pattern)
|
76
|
+
self =~ pattern
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
64
80
|
end
|
65
81
|
|
66
82
|
# Order matters for these:
|
@@ -91,13 +107,13 @@ require "graphql/analysis"
|
|
91
107
|
require "graphql/tracing"
|
92
108
|
require "graphql/dig"
|
93
109
|
require "graphql/execution"
|
110
|
+
require "graphql/runtime_type_error"
|
111
|
+
require "graphql/unresolved_type_error"
|
112
|
+
require "graphql/invalid_null_error"
|
94
113
|
require "graphql/schema"
|
95
114
|
require "graphql/query"
|
96
115
|
require "graphql/directive"
|
97
116
|
require "graphql/execution"
|
98
|
-
require "graphql/runtime_type_error"
|
99
|
-
require "graphql/unresolved_type_error"
|
100
|
-
require "graphql/invalid_null_error"
|
101
117
|
require "graphql/types"
|
102
118
|
require "graphql/relay"
|
103
119
|
require "graphql/boolean_type"
|
data/lib/graphql/argument.rb
CHANGED
@@ -3,14 +3,14 @@ module GraphQL
|
|
3
3
|
# @api deprecated
|
4
4
|
class Argument
|
5
5
|
include GraphQL::Define::InstanceDefinable
|
6
|
-
accepts_definitions :name, :type, :description, :default_value, :as, :prepare, :method_access
|
6
|
+
accepts_definitions :name, :type, :description, :default_value, :as, :prepare, :method_access, :deprecation_reason
|
7
7
|
attr_reader :default_value
|
8
|
-
attr_accessor :description, :name, :as
|
8
|
+
attr_accessor :description, :name, :as, :deprecation_reason
|
9
9
|
attr_accessor :ast_node
|
10
10
|
attr_accessor :method_access
|
11
11
|
alias :graphql_name :name
|
12
12
|
|
13
|
-
ensure_defined(:name, :description, :default_value, :type=, :type, :as, :expose_as, :prepare, :method_access)
|
13
|
+
ensure_defined(:name, :description, :default_value, :type=, :type, :as, :expose_as, :prepare, :method_access, :deprecation_reason)
|
14
14
|
|
15
15
|
# @api private
|
16
16
|
module DefaultPrepare
|
@@ -15,7 +15,8 @@ module GraphQL
|
|
15
15
|
when "validate", "analyze_query", "execute_query", "execute_query_lazy"
|
16
16
|
metadata[:query] || metadata[:queries]
|
17
17
|
when "execute_field", "execute_field_lazy"
|
18
|
-
|
18
|
+
# The interpreter passes `query:`, legacy passes `context:`
|
19
|
+
metadata[:context] || ((q = metadata[:query]) && q.context)
|
19
20
|
else
|
20
21
|
# Custom key, no backtrace data for this
|
21
22
|
nil
|
data/lib/graphql/directive.rb
CHANGED
@@ -93,6 +93,16 @@ module GraphQL
|
|
93
93
|
tracer.trace("execute_query_lazy", {multiplex: multiplex, query: query}) do
|
94
94
|
Interpreter::Resolve.resolve_all(final_values)
|
95
95
|
end
|
96
|
+
queries.each do |query|
|
97
|
+
runtime = query.context.namespace(:interpreter)[:runtime]
|
98
|
+
if runtime
|
99
|
+
runtime.delete_interpreter_context(:current_path)
|
100
|
+
runtime.delete_interpreter_context(:current_field)
|
101
|
+
runtime.delete_interpreter_context(:current_object)
|
102
|
+
runtime.delete_interpreter_context(:current_arguments)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
nil
|
96
106
|
end
|
97
107
|
|
98
108
|
class ListResultFailedError < GraphQL::Error
|
@@ -24,7 +24,7 @@ module GraphQL
|
|
24
24
|
# @return [Hash{Symbol => ArgumentValue}]
|
25
25
|
attr_reader :argument_values
|
26
26
|
|
27
|
-
def_delegators :@keyword_arguments, :key?, :[], :keys, :each, :values
|
27
|
+
def_delegators :@keyword_arguments, :key?, :[], :fetch, :keys, :each, :values
|
28
28
|
def_delegators :@argument_values, :each_value
|
29
29
|
|
30
30
|
def inspect
|
@@ -43,23 +43,25 @@ module GraphQL
|
|
43
43
|
# might be stored up in lazies.
|
44
44
|
# @return [void]
|
45
45
|
def run_eager
|
46
|
-
|
47
46
|
root_operation = query.selected_operation
|
48
47
|
root_op_type = root_operation.operation_type || "query"
|
49
48
|
root_type = schema.root_type_for_operation(root_op_type)
|
50
49
|
path = []
|
51
|
-
|
52
|
-
|
50
|
+
set_interpreter_context(:current_object, query.root_value)
|
51
|
+
set_interpreter_context(:current_path, path)
|
53
52
|
object_proxy = authorized_new(root_type, query.root_value, context, path)
|
54
53
|
object_proxy = schema.sync_lazy(object_proxy)
|
55
54
|
if object_proxy.nil?
|
56
55
|
# Root .authorized? returned false.
|
57
56
|
write_in_response(path, nil)
|
58
|
-
nil
|
59
57
|
else
|
60
58
|
evaluate_selections(path, context.scoped_context, object_proxy, root_type, root_operation.selections, root_operation_type: root_op_type)
|
61
|
-
nil
|
62
59
|
end
|
60
|
+
delete_interpreter_context(:current_path)
|
61
|
+
delete_interpreter_context(:current_field)
|
62
|
+
delete_interpreter_context(:current_object)
|
63
|
+
delete_interpreter_context(:current_arguments)
|
64
|
+
nil
|
63
65
|
end
|
64
66
|
|
65
67
|
def gather_selections(owner_object, owner_type, selections, selections_by_name)
|
@@ -117,8 +119,8 @@ module GraphQL
|
|
117
119
|
end
|
118
120
|
|
119
121
|
def evaluate_selections(path, scoped_context, owner_object, owner_type, selections, root_operation_type: nil)
|
120
|
-
|
121
|
-
|
122
|
+
set_interpreter_context(:current_object, owner_object)
|
123
|
+
set_interpreter_context(:current_path, path)
|
122
124
|
selections_by_name = {}
|
123
125
|
gather_selections(owner_object, owner_type, selections, selections_by_name)
|
124
126
|
selections_by_name.each do |result_name, field_ast_nodes_or_ast_node|
|
@@ -157,8 +159,8 @@ module GraphQL
|
|
157
159
|
# to propagate `null`
|
158
160
|
set_type_at_path(next_path, return_type)
|
159
161
|
# Set this before calling `run_with_directives`, so that the directive can have the latest path
|
160
|
-
|
161
|
-
|
162
|
+
set_interpreter_context(:current_path, next_path)
|
163
|
+
set_interpreter_context(:current_field, field_defn)
|
162
164
|
|
163
165
|
context.scoped_context = scoped_context
|
164
166
|
object = owner_object
|
@@ -170,13 +172,13 @@ module GraphQL
|
|
170
172
|
begin
|
171
173
|
kwarg_arguments = arguments(object, field_defn, ast_node)
|
172
174
|
rescue GraphQL::ExecutionError => e
|
173
|
-
continue_value(next_path, e, field_defn, return_type.non_null?, ast_node)
|
175
|
+
continue_value(next_path, e, owner_type, field_defn, return_type.non_null?, ast_node)
|
174
176
|
next
|
175
177
|
end
|
176
178
|
|
177
179
|
after_lazy(kwarg_arguments, owner: owner_type, field: field_defn, path: next_path, scoped_context: context.scoped_context, owner_object: object, arguments: kwarg_arguments) do |resolved_arguments|
|
178
180
|
if resolved_arguments.is_a? GraphQL::ExecutionError
|
179
|
-
continue_value(next_path, resolved_arguments, field_defn, return_type.non_null?, ast_node)
|
181
|
+
continue_value(next_path, resolved_arguments, owner_type, field_defn, return_type.non_null?, ast_node)
|
180
182
|
next
|
181
183
|
end
|
182
184
|
|
@@ -206,7 +208,7 @@ module GraphQL
|
|
206
208
|
end
|
207
209
|
end
|
208
210
|
|
209
|
-
|
211
|
+
set_interpreter_context(:current_arguments, kwarg_arguments)
|
210
212
|
|
211
213
|
# Optimize for the case that field is selected only once
|
212
214
|
if field_ast_nodes.nil? || field_ast_nodes.size == 1
|
@@ -228,12 +230,12 @@ module GraphQL
|
|
228
230
|
err
|
229
231
|
end
|
230
232
|
after_lazy(app_result, owner: owner_type, field: field_defn, path: next_path, scoped_context: context.scoped_context, owner_object: object, arguments: kwarg_arguments) do |inner_result|
|
231
|
-
continue_value = continue_value(next_path, inner_result, field_defn, return_type.non_null?, ast_node)
|
233
|
+
continue_value = continue_value(next_path, inner_result, owner_type, field_defn, return_type.non_null?, ast_node)
|
232
234
|
if RawValue === continue_value
|
233
235
|
# Write raw value directly to the response without resolving nested objects
|
234
236
|
write_in_response(next_path, continue_value.resolve)
|
235
237
|
elsif HALT != continue_value
|
236
|
-
continue_field(next_path, continue_value, field_defn, return_type, ast_node, next_selections, false, object, kwarg_arguments)
|
238
|
+
continue_field(next_path, continue_value, owner_type, field_defn, return_type, ast_node, next_selections, false, object, kwarg_arguments)
|
237
239
|
end
|
238
240
|
end
|
239
241
|
end
|
@@ -251,10 +253,10 @@ module GraphQL
|
|
251
253
|
end
|
252
254
|
|
253
255
|
HALT = Object.new
|
254
|
-
def continue_value(path, value, field, is_non_null, ast_node)
|
256
|
+
def continue_value(path, value, parent_type, field, is_non_null, ast_node)
|
255
257
|
if value.nil?
|
256
258
|
if is_non_null
|
257
|
-
err =
|
259
|
+
err = parent_type::InvalidNullError.new(parent_type, field, value)
|
258
260
|
write_invalid_null_in_response(path, err)
|
259
261
|
else
|
260
262
|
write_in_response(path, nil)
|
@@ -281,7 +283,7 @@ module GraphQL
|
|
281
283
|
err
|
282
284
|
end
|
283
285
|
|
284
|
-
continue_value(path, next_value, field, is_non_null, ast_node)
|
286
|
+
continue_value(path, next_value, parent_type, field, is_non_null, ast_node)
|
285
287
|
elsif GraphQL::Execution::Execute::SKIP == value
|
286
288
|
HALT
|
287
289
|
else
|
@@ -297,49 +299,49 @@ module GraphQL
|
|
297
299
|
# Location information from `path` and `ast_node`.
|
298
300
|
#
|
299
301
|
# @return [Lazy, Array, Hash, Object] Lazy, Array, and Hash are all traversed to resolve lazy values later
|
300
|
-
def continue_field(path, value, field,
|
301
|
-
case
|
302
|
+
def continue_field(path, value, owner_type, field, current_type, ast_node, next_selections, is_non_null, owner_object, arguments) # rubocop:disable Metrics/ParameterLists
|
303
|
+
case current_type.kind.name
|
302
304
|
when "SCALAR", "ENUM"
|
303
|
-
r =
|
305
|
+
r = current_type.coerce_result(value, context)
|
304
306
|
write_in_response(path, r)
|
305
307
|
r
|
306
308
|
when "UNION", "INTERFACE"
|
307
|
-
resolved_type_or_lazy, resolved_value = resolve_type(
|
309
|
+
resolved_type_or_lazy, resolved_value = resolve_type(current_type, value, path)
|
308
310
|
resolved_value ||= value
|
309
311
|
|
310
|
-
after_lazy(resolved_type_or_lazy, owner:
|
311
|
-
possible_types = query.possible_types(
|
312
|
+
after_lazy(resolved_type_or_lazy, owner: current_type, path: path, scoped_context: context.scoped_context, field: field, owner_object: owner_object, arguments: arguments, trace: false) do |resolved_type|
|
313
|
+
possible_types = query.possible_types(current_type)
|
312
314
|
|
313
315
|
if !possible_types.include?(resolved_type)
|
314
|
-
parent_type = field.
|
315
|
-
err_class =
|
316
|
+
parent_type = field.owner_type
|
317
|
+
err_class = current_type::UnresolvedTypeError
|
316
318
|
type_error = err_class.new(resolved_value, field, parent_type, resolved_type, possible_types)
|
317
319
|
schema.type_error(type_error, context)
|
318
320
|
write_in_response(path, nil)
|
319
321
|
nil
|
320
322
|
else
|
321
|
-
continue_field(path, resolved_value, field, resolved_type, ast_node, next_selections, is_non_null, owner_object, arguments)
|
323
|
+
continue_field(path, resolved_value, owner_type, field, resolved_type, ast_node, next_selections, is_non_null, owner_object, arguments)
|
322
324
|
end
|
323
325
|
end
|
324
326
|
when "OBJECT"
|
325
327
|
object_proxy = begin
|
326
|
-
authorized_new(
|
328
|
+
authorized_new(current_type, value, context, path)
|
327
329
|
rescue GraphQL::ExecutionError => err
|
328
330
|
err
|
329
331
|
end
|
330
|
-
after_lazy(object_proxy, owner:
|
331
|
-
continue_value = continue_value(path, inner_object, field, is_non_null, ast_node)
|
332
|
+
after_lazy(object_proxy, owner: current_type, path: path, scoped_context: context.scoped_context, field: field, owner_object: owner_object, arguments: arguments, trace: false) do |inner_object|
|
333
|
+
continue_value = continue_value(path, inner_object, owner_type, field, is_non_null, ast_node)
|
332
334
|
if HALT != continue_value
|
333
335
|
response_hash = {}
|
334
336
|
write_in_response(path, response_hash)
|
335
|
-
evaluate_selections(path, context.scoped_context, continue_value,
|
337
|
+
evaluate_selections(path, context.scoped_context, continue_value, current_type, next_selections)
|
336
338
|
response_hash
|
337
339
|
end
|
338
340
|
end
|
339
341
|
when "LIST"
|
340
342
|
response_list = []
|
341
343
|
write_in_response(path, response_list)
|
342
|
-
inner_type =
|
344
|
+
inner_type = current_type.of_type
|
343
345
|
idx = 0
|
344
346
|
scoped_context = context.scoped_context
|
345
347
|
begin
|
@@ -351,9 +353,9 @@ module GraphQL
|
|
351
353
|
set_type_at_path(next_path, inner_type)
|
352
354
|
# This will update `response_list` with the lazy
|
353
355
|
after_lazy(inner_value, owner: inner_type, path: next_path, scoped_context: scoped_context, field: field, owner_object: owner_object, arguments: arguments) do |inner_inner_value|
|
354
|
-
continue_value = continue_value(next_path, inner_inner_value, field, inner_type.non_null?, ast_node)
|
356
|
+
continue_value = continue_value(next_path, inner_inner_value, owner_type, field, inner_type.non_null?, ast_node)
|
355
357
|
if HALT != continue_value
|
356
|
-
continue_field(next_path, continue_value, field, inner_type, ast_node, next_selections, false, owner_object, arguments)
|
358
|
+
continue_field(next_path, continue_value, owner_type, field, inner_type, ast_node, next_selections, false, owner_object, arguments)
|
357
359
|
end
|
358
360
|
end
|
359
361
|
end
|
@@ -370,12 +372,12 @@ module GraphQL
|
|
370
372
|
|
371
373
|
response_list
|
372
374
|
when "NON_NULL"
|
373
|
-
inner_type =
|
375
|
+
inner_type = current_type.of_type
|
374
376
|
# Don't `set_type_at_path` because we want the static type,
|
375
377
|
# we're going to use that to determine whether a `nil` should be propagated or not.
|
376
|
-
continue_field(path, value, field, inner_type, ast_node, next_selections, true, owner_object, arguments)
|
378
|
+
continue_field(path, value, owner_type, field, inner_type, ast_node, next_selections, true, owner_object, arguments)
|
377
379
|
else
|
378
|
-
raise "Invariant: Unhandled type kind #{
|
380
|
+
raise "Invariant: Unhandled type kind #{current_type.kind} (#{current_type})"
|
379
381
|
end
|
380
382
|
end
|
381
383
|
|
@@ -419,16 +421,16 @@ module GraphQL
|
|
419
421
|
# @param trace [Boolean] If `false`, don't wrap this with field tracing
|
420
422
|
# @return [GraphQL::Execution::Lazy, Object] If loading `object` will be deferred, it's a wrapper over it.
|
421
423
|
def after_lazy(lazy_obj, owner:, field:, path:, scoped_context:, owner_object:, arguments:, eager: false, trace: true, &block)
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
424
|
+
set_interpreter_context(:current_object, owner_object)
|
425
|
+
set_interpreter_context(:current_arguments, arguments)
|
426
|
+
set_interpreter_context(:current_path, path)
|
427
|
+
set_interpreter_context(:current_field, field)
|
426
428
|
if schema.lazy?(lazy_obj)
|
427
429
|
lazy = GraphQL::Execution::Lazy.new(path: path, field: field) do
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
430
|
+
set_interpreter_context(:current_path, path)
|
431
|
+
set_interpreter_context(:current_field, field)
|
432
|
+
set_interpreter_context(:current_object, owner_object)
|
433
|
+
set_interpreter_context(:current_arguments, arguments)
|
432
434
|
context.scoped_context = scoped_context
|
433
435
|
# Wrap the execution of _this_ method with tracing,
|
434
436
|
# but don't wrap the continuation below
|
@@ -460,8 +462,9 @@ module GraphQL
|
|
460
462
|
end
|
461
463
|
|
462
464
|
def arguments(graphql_object, arg_owner, ast_node)
|
463
|
-
# Don't cache arguments if field extras are requested since
|
464
|
-
if arg_owner.arguments_statically_coercible? &&
|
465
|
+
# Don't cache arguments if field extras or extensions are requested since they can mutate the argument data structure
|
466
|
+
if arg_owner.arguments_statically_coercible? &&
|
467
|
+
(!arg_owner.is_a?(GraphQL::Schema::Field) || (arg_owner.extras.empty? && arg_owner.extensions.empty?))
|
465
468
|
query.arguments_for(ast_node, arg_owner)
|
466
469
|
else
|
467
470
|
# The arguments must be prepared in the context of the given object
|
@@ -538,6 +541,18 @@ module GraphQL
|
|
538
541
|
res && res[:__dead]
|
539
542
|
end
|
540
543
|
|
544
|
+
# Set this pair in the Query context, but also in the interpeter namespace,
|
545
|
+
# for compatibility.
|
546
|
+
def set_interpreter_context(key, value)
|
547
|
+
@interpreter_context[key] = value
|
548
|
+
@context[key] = value
|
549
|
+
end
|
550
|
+
|
551
|
+
def delete_interpreter_context(key)
|
552
|
+
@interpreter_context.delete(key)
|
553
|
+
@context.delete(key)
|
554
|
+
end
|
555
|
+
|
541
556
|
def resolve_type(type, value, path)
|
542
557
|
trace_payload = { context: context, type: type, object: value, path: path }
|
543
558
|
resolved_type, resolved_value = query.trace("resolve_type", trace_payload) do
|