graphql 2.4.3 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/graphql/analysis/analyzer.rb +2 -1
- data/lib/graphql/analysis/visitor.rb +38 -41
- data/lib/graphql/analysis.rb +15 -12
- data/lib/graphql/autoload.rb +38 -0
- data/lib/graphql/backtrace/table.rb +118 -55
- data/lib/graphql/backtrace.rb +1 -19
- data/lib/graphql/current.rb +6 -1
- data/lib/graphql/dashboard/detailed_traces.rb +47 -0
- data/lib/graphql/dashboard/installable.rb +22 -0
- data/lib/graphql/dashboard/limiters.rb +93 -0
- data/lib/graphql/dashboard/operation_store.rb +199 -0
- data/lib/graphql/dashboard/statics/bootstrap-5.3.3.min.css +6 -0
- data/lib/graphql/dashboard/statics/bootstrap-5.3.3.min.js +7 -0
- data/lib/graphql/dashboard/statics/charts.min.css +1 -0
- data/lib/graphql/dashboard/statics/dashboard.css +30 -0
- data/lib/graphql/dashboard/statics/dashboard.js +143 -0
- data/lib/graphql/dashboard/statics/header-icon.png +0 -0
- data/lib/graphql/dashboard/statics/icon.png +0 -0
- data/lib/graphql/dashboard/subscriptions.rb +96 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/detailed_traces/traces/index.html.erb +45 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/landings/show.html.erb +18 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/limiters/limiters/show.html.erb +62 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/not_installed.html.erb +18 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/_form.html.erb +23 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/edit.html.erb +21 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/index.html.erb +69 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/clients/new.html.erb +7 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/index_entries/index.html.erb +39 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/index_entries/show.html.erb +32 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/operations/index.html.erb +81 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/operation_store/operations/show.html.erb +71 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/subscriptions/show.html.erb +41 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/topics/index.html.erb +55 -0
- data/lib/graphql/dashboard/views/graphql/dashboard/subscriptions/topics/show.html.erb +40 -0
- data/lib/graphql/dashboard/views/layouts/graphql/dashboard/application.html.erb +108 -0
- data/lib/graphql/dashboard.rb +158 -0
- data/lib/graphql/dataloader/active_record_association_source.rb +64 -0
- data/lib/graphql/dataloader/active_record_source.rb +26 -0
- data/lib/graphql/dataloader/async_dataloader.rb +21 -9
- data/lib/graphql/dataloader/null_dataloader.rb +1 -1
- data/lib/graphql/dataloader/source.rb +3 -3
- data/lib/graphql/dataloader.rb +43 -14
- data/lib/graphql/execution/interpreter/resolve.rb +3 -3
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +34 -4
- data/lib/graphql/execution/interpreter/runtime.rb +94 -51
- data/lib/graphql/execution/interpreter.rb +16 -7
- data/lib/graphql/execution/multiplex.rb +1 -5
- data/lib/graphql/introspection/directive_location_enum.rb +1 -1
- data/lib/graphql/invalid_name_error.rb +1 -1
- data/lib/graphql/invalid_null_error.rb +5 -15
- data/lib/graphql/language/cache.rb +13 -0
- data/lib/graphql/language/document_from_schema_definition.rb +8 -7
- data/lib/graphql/language/lexer.rb +11 -4
- data/lib/graphql/language/nodes.rb +3 -0
- data/lib/graphql/language/parser.rb +15 -8
- data/lib/graphql/language/printer.rb +8 -8
- data/lib/graphql/language/static_visitor.rb +37 -33
- data/lib/graphql/language/visitor.rb +59 -55
- data/lib/graphql/pagination/connection.rb +1 -1
- data/lib/graphql/query/context/scoped_context.rb +1 -1
- data/lib/graphql/query/context.rb +6 -5
- data/lib/graphql/query/variable_validation_error.rb +1 -1
- data/lib/graphql/query.rb +19 -23
- data/lib/graphql/railtie.rb +7 -0
- data/lib/graphql/schema/addition.rb +1 -1
- data/lib/graphql/schema/argument.rb +7 -8
- data/lib/graphql/schema/build_from_definition.rb +99 -53
- data/lib/graphql/schema/directive/flagged.rb +3 -1
- data/lib/graphql/schema/directive.rb +2 -2
- data/lib/graphql/schema/enum.rb +36 -1
- data/lib/graphql/schema/enum_value.rb +1 -1
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +27 -13
- data/lib/graphql/schema/field_extension.rb +1 -1
- data/lib/graphql/schema/has_single_input_argument.rb +3 -1
- data/lib/graphql/schema/input_object.rb +77 -40
- data/lib/graphql/schema/interface.rb +3 -2
- data/lib/graphql/schema/loader.rb +1 -1
- data/lib/graphql/schema/member/has_arguments.rb +25 -17
- data/lib/graphql/schema/member/has_dataloader.rb +60 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +15 -0
- data/lib/graphql/schema/member/has_directives.rb +4 -4
- data/lib/graphql/schema/member/has_fields.rb +19 -1
- data/lib/graphql/schema/member/has_interfaces.rb +5 -5
- data/lib/graphql/schema/member/has_validators.rb +1 -1
- data/lib/graphql/schema/member/scoped.rb +1 -1
- data/lib/graphql/schema/member/type_system_helpers.rb +1 -1
- data/lib/graphql/schema/member.rb +1 -0
- data/lib/graphql/schema/object.rb +25 -8
- data/lib/graphql/schema/relay_classic_mutation.rb +0 -1
- data/lib/graphql/schema/resolver.rb +12 -10
- data/lib/graphql/schema/subscription.rb +52 -6
- data/lib/graphql/schema/union.rb +1 -1
- data/lib/graphql/schema/validator/required_validator.rb +23 -6
- data/lib/graphql/schema/validator.rb +1 -1
- data/lib/graphql/schema/visibility/migration.rb +1 -0
- data/lib/graphql/schema/visibility/profile.rb +95 -243
- data/lib/graphql/schema/visibility/visit.rb +190 -0
- data/lib/graphql/schema/visibility.rb +169 -28
- data/lib/graphql/schema/warden.rb +18 -5
- data/lib/graphql/schema.rb +93 -44
- data/lib/graphql/static_validation/all_rules.rb +1 -1
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +1 -1
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +1 -1
- data/lib/graphql/static_validation/rules/not_single_subscription_error.rb +25 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +1 -1
- data/lib/graphql/static_validation/rules/subscription_root_exists_and_single_subscription_selection.rb +26 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
- data/lib/graphql/static_validation/validation_context.rb +1 -0
- data/lib/graphql/static_validation/validator.rb +6 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +1 -1
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +12 -10
- data/lib/graphql/subscriptions/event.rb +12 -1
- data/lib/graphql/subscriptions/serialize.rb +1 -1
- data/lib/graphql/subscriptions.rb +1 -1
- data/lib/graphql/testing/helpers.rb +7 -4
- data/lib/graphql/tracing/active_support_notifications_trace.rb +14 -3
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +1 -1
- data/lib/graphql/tracing/appoptics_trace.rb +9 -1
- data/lib/graphql/tracing/appoptics_tracing.rb +7 -0
- data/lib/graphql/tracing/appsignal_trace.rb +32 -55
- data/lib/graphql/tracing/appsignal_tracing.rb +2 -0
- data/lib/graphql/tracing/call_legacy_tracers.rb +66 -0
- data/lib/graphql/tracing/data_dog_trace.rb +46 -158
- data/lib/graphql/tracing/data_dog_tracing.rb +2 -0
- data/lib/graphql/tracing/detailed_trace/memory_backend.rb +60 -0
- data/lib/graphql/tracing/detailed_trace/redis_backend.rb +72 -0
- data/lib/graphql/tracing/detailed_trace.rb +93 -0
- data/lib/graphql/tracing/legacy_hooks_trace.rb +1 -0
- data/lib/graphql/tracing/legacy_trace.rb +4 -61
- data/lib/graphql/tracing/monitor_trace.rb +283 -0
- data/lib/graphql/tracing/new_relic_trace.rb +47 -54
- data/lib/graphql/tracing/new_relic_tracing.rb +2 -0
- data/lib/graphql/tracing/notifications_trace.rb +182 -34
- data/lib/graphql/tracing/notifications_tracing.rb +2 -0
- data/lib/graphql/tracing/null_trace.rb +9 -0
- data/lib/graphql/tracing/perfetto_trace/trace.proto +141 -0
- data/lib/graphql/tracing/perfetto_trace/trace_pb.rb +33 -0
- data/lib/graphql/tracing/perfetto_trace.rb +734 -0
- data/lib/graphql/tracing/platform_trace.rb +5 -0
- data/lib/graphql/tracing/prometheus_trace/graphql_collector.rb +2 -0
- data/lib/graphql/tracing/prometheus_trace.rb +72 -68
- data/lib/graphql/tracing/prometheus_tracing.rb +2 -0
- data/lib/graphql/tracing/scout_trace.rb +32 -55
- data/lib/graphql/tracing/scout_tracing.rb +2 -0
- data/lib/graphql/tracing/sentry_trace.rb +62 -94
- data/lib/graphql/tracing/statsd_trace.rb +33 -41
- data/lib/graphql/tracing/statsd_tracing.rb +2 -0
- data/lib/graphql/tracing/trace.rb +111 -1
- data/lib/graphql/tracing.rb +31 -30
- data/lib/graphql/types/relay/connection_behaviors.rb +3 -3
- data/lib/graphql/types/relay/edge_behaviors.rb +2 -2
- data/lib/graphql/types.rb +18 -11
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +55 -47
- metadata +146 -11
- data/lib/graphql/backtrace/inspect_result.rb +0 -38
- data/lib/graphql/backtrace/trace.rb +0 -93
- data/lib/graphql/backtrace/tracer.rb +0 -80
- data/lib/graphql/schema/null_mask.rb +0 -11
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cff992b51cd3efae382a362bc5708e8dce5060efb48cf1944560262a59276283
|
4
|
+
data.tar.gz: 206fd93c0504f9072f8af62a18557a9e0380664b1f8836acd38426ee44e9eaf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 293369e23e4baee72a07481b6a6015be003e2557469ab3b30e1ee82d79bfaf6004218a5fe0a85033de8e92b3ae475508bf445e5906ec2a81c4df53c2b25add49
|
7
|
+
data.tar.gz: fafe652c92d2655ad39a16fb61252b33b27eee4e10476a5cc40ab7fd3c1e81a56f9e67b81f6a9ba1da67ba76c7112e756973a236287c634bae9cf66fb7ed3e3e
|
@@ -42,6 +42,7 @@ module GraphQL
|
|
42
42
|
raise GraphQL::RequiredImplementationMissingError
|
43
43
|
end
|
44
44
|
|
45
|
+
# rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time
|
45
46
|
class << self
|
46
47
|
private
|
47
48
|
|
@@ -72,7 +73,7 @@ module GraphQL
|
|
72
73
|
build_visitor_hooks :variable_definition
|
73
74
|
build_visitor_hooks :variable_identifier
|
74
75
|
build_visitor_hooks :abstract_node
|
75
|
-
|
76
|
+
# rubocop:enable Development/NoEvalCop
|
76
77
|
protected
|
77
78
|
|
78
79
|
# @return [GraphQL::Query, GraphQL::Execution::Multiplex] Whatever this analyzer is analyzing
|
@@ -10,7 +10,7 @@ module GraphQL
|
|
10
10
|
#
|
11
11
|
# @see {GraphQL::Analysis::Analyzer} AST Analyzers for queries
|
12
12
|
class Visitor < GraphQL::Language::StaticVisitor
|
13
|
-
def initialize(query:, analyzers:)
|
13
|
+
def initialize(query:, analyzers:, timeout:)
|
14
14
|
@analyzers = analyzers
|
15
15
|
@path = []
|
16
16
|
@object_types = []
|
@@ -24,6 +24,11 @@ module GraphQL
|
|
24
24
|
@types = query.types
|
25
25
|
@response_path = []
|
26
26
|
@skip_stack = [false]
|
27
|
+
@timeout_time = if timeout
|
28
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) + timeout
|
29
|
+
else
|
30
|
+
Float::INFINITY
|
31
|
+
end
|
27
32
|
super(query.selected_operation)
|
28
33
|
end
|
29
34
|
|
@@ -64,6 +69,7 @@ module GraphQL
|
|
64
69
|
@response_path.dup
|
65
70
|
end
|
66
71
|
|
72
|
+
# rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time
|
67
73
|
# Visitor Hooks
|
68
74
|
[
|
69
75
|
:operation_definition, :fragment_definition,
|
@@ -72,28 +78,26 @@ module GraphQL
|
|
72
78
|
module_eval <<-RUBY, __FILE__, __LINE__
|
73
79
|
def call_on_enter_#{node_type}(node, parent)
|
74
80
|
@analyzers.each do |a|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
@rescued_errors << err
|
79
|
-
end
|
81
|
+
a.on_enter_#{node_type}(node, parent, self)
|
82
|
+
rescue AnalysisError => err
|
83
|
+
@rescued_errors << err
|
80
84
|
end
|
81
85
|
end
|
82
86
|
|
83
87
|
def call_on_leave_#{node_type}(node, parent)
|
84
88
|
@analyzers.each do |a|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
@rescued_errors << err
|
89
|
-
end
|
89
|
+
a.on_leave_#{node_type}(node, parent, self)
|
90
|
+
rescue AnalysisError => err
|
91
|
+
@rescued_errors << err
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
95
|
RUBY
|
94
96
|
end
|
97
|
+
# rubocop:enable Development/NoEvalCop
|
95
98
|
|
96
99
|
def on_operation_definition(node, parent)
|
100
|
+
check_timeout
|
97
101
|
object_type = @schema.root_type_for_operation(node.operation_type)
|
98
102
|
@object_types.push(object_type)
|
99
103
|
@path.push("#{node.operation_type}#{node.name ? " #{node.name}" : ""}")
|
@@ -104,31 +108,27 @@ module GraphQL
|
|
104
108
|
@path.pop
|
105
109
|
end
|
106
110
|
|
107
|
-
def on_fragment_definition(node, parent)
|
108
|
-
on_fragment_with_type(node) do
|
109
|
-
@path.push("fragment #{node.name}")
|
110
|
-
@in_fragment_def = false
|
111
|
-
call_on_enter_fragment_definition(node, parent)
|
112
|
-
super
|
113
|
-
@in_fragment_def = false
|
114
|
-
call_on_leave_fragment_definition(node, parent)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
111
|
def on_inline_fragment(node, parent)
|
119
|
-
|
120
|
-
|
121
|
-
@
|
122
|
-
|
123
|
-
|
124
|
-
call_on_enter_inline_fragment(node, parent)
|
125
|
-
super
|
126
|
-
@skipping = @skip_stack.pop
|
127
|
-
call_on_leave_inline_fragment(node, parent)
|
112
|
+
check_timeout
|
113
|
+
object_type = if node.type
|
114
|
+
@types.type(node.type.name)
|
115
|
+
else
|
116
|
+
@object_types.last
|
128
117
|
end
|
118
|
+
@object_types.push(object_type)
|
119
|
+
@path.push("...#{node.type ? " on #{node.type.name}" : ""}")
|
120
|
+
@skipping = @skip_stack.last || skip?(node)
|
121
|
+
@skip_stack << @skipping
|
122
|
+
call_on_enter_inline_fragment(node, parent)
|
123
|
+
super
|
124
|
+
@skipping = @skip_stack.pop
|
125
|
+
call_on_leave_inline_fragment(node, parent)
|
126
|
+
@object_types.pop
|
127
|
+
@path.pop
|
129
128
|
end
|
130
129
|
|
131
130
|
def on_field(node, parent)
|
131
|
+
check_timeout
|
132
132
|
@response_path.push(node.alias || node.name)
|
133
133
|
parent_type = @object_types.last
|
134
134
|
# This could be nil if the previous field wasn't found:
|
@@ -156,6 +156,7 @@ module GraphQL
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def on_directive(node, parent)
|
159
|
+
check_timeout
|
159
160
|
directive_defn = @schema.directives[node.name]
|
160
161
|
@directive_definitions.push(directive_defn)
|
161
162
|
call_on_enter_directive(node, parent)
|
@@ -165,6 +166,7 @@ module GraphQL
|
|
165
166
|
end
|
166
167
|
|
167
168
|
def on_argument(node, parent)
|
169
|
+
check_timeout
|
168
170
|
argument_defn = if (arg = @argument_definitions.last)
|
169
171
|
arg_type = arg.type.unwrap
|
170
172
|
if arg_type.kind.input_object?
|
@@ -190,6 +192,7 @@ module GraphQL
|
|
190
192
|
end
|
191
193
|
|
192
194
|
def on_fragment_spread(node, parent)
|
195
|
+
check_timeout
|
193
196
|
@path.push("... #{node.name}")
|
194
197
|
@skipping = @skip_stack.last || skip?(node)
|
195
198
|
@skip_stack << @skipping
|
@@ -264,19 +267,13 @@ module GraphQL
|
|
264
267
|
|
265
268
|
def skip?(ast_node)
|
266
269
|
dir = ast_node.directives
|
267
|
-
dir.
|
270
|
+
!dir.empty? && !GraphQL::Execution::DirectiveChecks.include?(dir, query)
|
268
271
|
end
|
269
272
|
|
270
|
-
def
|
271
|
-
|
272
|
-
|
273
|
-
else
|
274
|
-
@object_types.last
|
273
|
+
def check_timeout
|
274
|
+
if Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) > @timeout_time
|
275
|
+
raise GraphQL::Analysis::TimeoutError
|
275
276
|
end
|
276
|
-
@object_types.push(object_type)
|
277
|
-
yield(node)
|
278
|
-
@object_types.pop
|
279
|
-
@path.pop
|
280
277
|
end
|
281
278
|
end
|
282
279
|
end
|
data/lib/graphql/analysis.rb
CHANGED
@@ -6,11 +6,16 @@ require "graphql/analysis/query_complexity"
|
|
6
6
|
require "graphql/analysis/max_query_complexity"
|
7
7
|
require "graphql/analysis/query_depth"
|
8
8
|
require "graphql/analysis/max_query_depth"
|
9
|
-
require "timeout"
|
10
|
-
|
11
9
|
module GraphQL
|
12
10
|
module Analysis
|
13
11
|
AST = self
|
12
|
+
|
13
|
+
class TimeoutError < AnalysisError
|
14
|
+
def initialize(...)
|
15
|
+
super("Timeout on validation of query")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
14
19
|
module_function
|
15
20
|
# Analyze a multiplex, and all queries within.
|
16
21
|
# Multiplex analyzers are ran for all queries, keeping state.
|
@@ -55,21 +60,19 @@ module GraphQL
|
|
55
60
|
.tap { _1.select!(&:analyze?) }
|
56
61
|
|
57
62
|
analyzers_to_run = query_analyzers + multiplex_analyzers
|
58
|
-
if analyzers_to_run.
|
63
|
+
if !analyzers_to_run.empty?
|
59
64
|
|
60
65
|
analyzers_to_run.select!(&:visit?)
|
61
|
-
if analyzers_to_run.
|
66
|
+
if !analyzers_to_run.empty?
|
62
67
|
visitor = GraphQL::Analysis::Visitor.new(
|
63
68
|
query: query,
|
64
|
-
analyzers: analyzers_to_run
|
69
|
+
analyzers: analyzers_to_run,
|
70
|
+
timeout: query.validate_timeout_remaining,
|
65
71
|
)
|
66
72
|
|
67
|
-
|
68
|
-
Timeout::timeout(query.validate_timeout_remaining) do
|
69
|
-
visitor.visit
|
70
|
-
end
|
73
|
+
visitor.visit
|
71
74
|
|
72
|
-
if visitor.rescued_errors.
|
75
|
+
if !visitor.rescued_errors.empty?
|
73
76
|
return visitor.rescued_errors
|
74
77
|
end
|
75
78
|
end
|
@@ -79,8 +82,8 @@ module GraphQL
|
|
79
82
|
[]
|
80
83
|
end
|
81
84
|
end
|
82
|
-
rescue
|
83
|
-
[
|
85
|
+
rescue TimeoutError => err
|
86
|
+
[err]
|
84
87
|
rescue GraphQL::UnauthorizedError, GraphQL::ExecutionError
|
85
88
|
# This error was raised during analysis and will be returned the client before execution
|
86
89
|
[]
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
# @see GraphQL::Railtie for automatic Rails integration
|
5
|
+
module Autoload
|
6
|
+
# Register a constant named `const_name` to be loaded from `path`.
|
7
|
+
# This is like `Kernel#autoload` but it tracks the constants so they can be eager-loaded with {#eager_load!}
|
8
|
+
# @param const_name [Symbol]
|
9
|
+
# @param path [String]
|
10
|
+
# @return [void]
|
11
|
+
def autoload(const_name, path)
|
12
|
+
@_eagerloaded_constants ||= []
|
13
|
+
@_eagerloaded_constants << const_name
|
14
|
+
|
15
|
+
super const_name, path
|
16
|
+
end
|
17
|
+
|
18
|
+
# Call this to load this constant's `autoload` dependents and continue calling recursively
|
19
|
+
# @return [void]
|
20
|
+
def eager_load!
|
21
|
+
@_eager_loading = true
|
22
|
+
if @_eagerloaded_constants
|
23
|
+
@_eagerloaded_constants.each { |const_name| const_get(const_name) }
|
24
|
+
@_eagerloaded_constants = nil
|
25
|
+
end
|
26
|
+
nil
|
27
|
+
ensure
|
28
|
+
@_eager_loading = false
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# @return [Boolean] `true` if GraphQL-Ruby is currently eager-loading its constants
|
34
|
+
def eager_loading?
|
35
|
+
@_eager_loading ||= false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -36,7 +36,93 @@ module GraphQL
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def rows
|
39
|
-
@rows ||=
|
39
|
+
@rows ||= begin
|
40
|
+
query = @context.query
|
41
|
+
query_ctx = @context
|
42
|
+
runtime_inst = query_ctx.namespace(:interpreter_runtime)[:runtime]
|
43
|
+
result = runtime_inst.instance_variable_get(:@response)
|
44
|
+
rows = []
|
45
|
+
result_path = []
|
46
|
+
last_part = nil
|
47
|
+
path = @context.current_path
|
48
|
+
path.each do |path_part|
|
49
|
+
value = value_at(runtime_inst, result_path)
|
50
|
+
|
51
|
+
if result_path.empty?
|
52
|
+
name = query.selected_operation.operation_type || "query"
|
53
|
+
if (n = query.selected_operation_name)
|
54
|
+
name += " #{n}"
|
55
|
+
end
|
56
|
+
args = query.variables
|
57
|
+
else
|
58
|
+
name = result.graphql_field.path
|
59
|
+
args = result.graphql_arguments
|
60
|
+
end
|
61
|
+
|
62
|
+
object = result.graphql_parent ? result.graphql_parent.graphql_application_value : result.graphql_application_value
|
63
|
+
object = object.object.inspect
|
64
|
+
|
65
|
+
rows << [
|
66
|
+
result.ast_node.position.join(":"),
|
67
|
+
name,
|
68
|
+
"#{object}",
|
69
|
+
args.to_h.inspect,
|
70
|
+
inspect_result(value),
|
71
|
+
]
|
72
|
+
|
73
|
+
result_path << path_part
|
74
|
+
if path_part == path.last
|
75
|
+
last_part = path_part
|
76
|
+
else
|
77
|
+
result = result[path_part]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
object = result.graphql_application_value.object.inspect
|
82
|
+
ast_node = nil
|
83
|
+
result.graphql_selections.each do |s|
|
84
|
+
found_ast_node = find_ast_node(s, last_part)
|
85
|
+
if found_ast_node
|
86
|
+
ast_node = found_ast_node
|
87
|
+
break
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if ast_node
|
92
|
+
field_defn = query.get_field(result.graphql_result_type, ast_node.name)
|
93
|
+
args = query.arguments_for(ast_node, field_defn).to_h
|
94
|
+
field_path = field_defn.path
|
95
|
+
if ast_node.alias
|
96
|
+
field_path += " as #{ast_node.alias}"
|
97
|
+
end
|
98
|
+
|
99
|
+
rows << [
|
100
|
+
ast_node.position.join(":"),
|
101
|
+
field_path,
|
102
|
+
"#{object}",
|
103
|
+
args.inspect,
|
104
|
+
inspect_result(@override_value)
|
105
|
+
]
|
106
|
+
end
|
107
|
+
|
108
|
+
rows << HEADERS
|
109
|
+
rows.reverse!
|
110
|
+
rows
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def find_ast_node(node, last_part)
|
115
|
+
return nil unless node
|
116
|
+
return node if node.respond_to?(:alias) && node.respond_to?(:name) && (node.alias == last_part || node.name == last_part)
|
117
|
+
return nil unless node.respond_to?(:selections)
|
118
|
+
return nil if node.selections.nil? || node.selections.empty?
|
119
|
+
|
120
|
+
node.selections.each do |child|
|
121
|
+
child_ast_node = find_ast_node(child, last_part)
|
122
|
+
return child_ast_node if child_ast_node
|
123
|
+
end
|
124
|
+
|
125
|
+
nil
|
40
126
|
end
|
41
127
|
|
42
128
|
# @return [String]
|
@@ -75,67 +161,44 @@ module GraphQL
|
|
75
161
|
table
|
76
162
|
end
|
77
163
|
|
78
|
-
# @return [Array] 5 items for a backtrace table (not `key`)
|
79
|
-
def build_rows(context_entry, rows:, top: false)
|
80
|
-
case context_entry
|
81
|
-
when Backtrace::Frame
|
82
|
-
field_alias = context_entry.ast_node.respond_to?(:alias) && context_entry.ast_node.alias
|
83
|
-
value = if top && @override_value
|
84
|
-
@override_value
|
85
|
-
else
|
86
|
-
value_at(@context.query.context.namespace(:interpreter_runtime)[:runtime], context_entry.path)
|
87
|
-
end
|
88
|
-
rows << [
|
89
|
-
"#{context_entry.ast_node ? context_entry.ast_node.position.join(":") : ""}",
|
90
|
-
"#{context_entry.field.path}#{field_alias ? " as #{field_alias}" : ""}",
|
91
|
-
"#{context_entry.object.object.inspect}",
|
92
|
-
context_entry.arguments.to_h.inspect, # rubocop:disable Development/ContextIsPassedCop -- unrelated method
|
93
|
-
Backtrace::InspectResult.inspect_result(value),
|
94
|
-
]
|
95
|
-
if (parent = context_entry.parent_frame)
|
96
|
-
build_rows(parent, rows: rows)
|
97
|
-
else
|
98
|
-
rows
|
99
|
-
end
|
100
|
-
when GraphQL::Query::Context
|
101
|
-
query = context_entry.query
|
102
|
-
op = query.selected_operation
|
103
|
-
if op
|
104
|
-
op_type = op.operation_type
|
105
|
-
position = "#{op.line}:#{op.col}"
|
106
|
-
else
|
107
|
-
op_type = "query"
|
108
|
-
position = "?:?"
|
109
|
-
end
|
110
|
-
op_name = query.selected_operation_name
|
111
|
-
object = query.root_value
|
112
|
-
if object.is_a?(GraphQL::Schema::Object)
|
113
|
-
object = object.object
|
114
|
-
end
|
115
|
-
value = value_at(context_entry.namespace(:interpreter_runtime)[:runtime], [])
|
116
|
-
rows << [
|
117
|
-
"#{position}",
|
118
|
-
"#{op_type}#{op_name ? " #{op_name}" : ""}",
|
119
|
-
"#{object.inspect}",
|
120
|
-
query.variables.to_h.inspect,
|
121
|
-
Backtrace::InspectResult.inspect_result(value),
|
122
|
-
]
|
123
|
-
else
|
124
|
-
raise "Unexpected get_rows subject #{context_entry.class} (#{context_entry.inspect})"
|
125
|
-
end
|
126
|
-
end
|
127
164
|
|
128
165
|
def value_at(runtime, path)
|
129
166
|
response = runtime.final_result
|
130
167
|
path.each do |key|
|
131
|
-
|
132
|
-
next
|
133
|
-
else
|
134
|
-
break
|
135
|
-
end
|
168
|
+
response && (response = response[key])
|
136
169
|
end
|
137
170
|
response
|
138
171
|
end
|
172
|
+
|
173
|
+
def inspect_result(obj)
|
174
|
+
case obj
|
175
|
+
when Hash
|
176
|
+
"{" +
|
177
|
+
obj.map do |key, val|
|
178
|
+
"#{key}: #{inspect_truncated(val)}"
|
179
|
+
end.join(", ") +
|
180
|
+
"}"
|
181
|
+
when Array
|
182
|
+
"[" +
|
183
|
+
obj.map { |v| inspect_truncated(v) }.join(", ") +
|
184
|
+
"]"
|
185
|
+
else
|
186
|
+
inspect_truncated(obj)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def inspect_truncated(obj)
|
191
|
+
case obj
|
192
|
+
when Hash
|
193
|
+
"{...}"
|
194
|
+
when Array
|
195
|
+
"[...]"
|
196
|
+
when GraphQL::Execution::Lazy
|
197
|
+
"(unresolved)"
|
198
|
+
else
|
199
|
+
"#{obj.inspect}"
|
200
|
+
end
|
201
|
+
end
|
139
202
|
end
|
140
203
|
end
|
141
204
|
end
|
data/lib/graphql/backtrace.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require "graphql/backtrace/inspect_result"
|
3
2
|
require "graphql/backtrace/table"
|
4
3
|
require "graphql/backtrace/traced_error"
|
5
|
-
require "graphql/backtrace/tracer"
|
6
|
-
require "graphql/backtrace/trace"
|
7
4
|
module GraphQL
|
8
5
|
# Wrap unhandled errors with {TracedError}.
|
9
6
|
#
|
@@ -24,7 +21,7 @@ module GraphQL
|
|
24
21
|
def_delegators :to_a, :each, :[]
|
25
22
|
|
26
23
|
def self.use(schema_defn)
|
27
|
-
schema_defn.
|
24
|
+
schema_defn.using_backtrace = true
|
28
25
|
end
|
29
26
|
|
30
27
|
def initialize(context, value: nil)
|
@@ -40,20 +37,5 @@ module GraphQL
|
|
40
37
|
def to_a
|
41
38
|
@table.to_backtrace
|
42
39
|
end
|
43
|
-
|
44
|
-
# Used for internal bookkeeping
|
45
|
-
# @api private
|
46
|
-
class Frame
|
47
|
-
attr_reader :path, :query, :ast_node, :object, :field, :arguments, :parent_frame
|
48
|
-
def initialize(path:, query:, ast_node:, object:, field:, arguments:, parent_frame:)
|
49
|
-
@path = path
|
50
|
-
@query = query
|
51
|
-
@ast_node = ast_node
|
52
|
-
@field = field
|
53
|
-
@object = object
|
54
|
-
@arguments = arguments
|
55
|
-
@parent_frame = parent_frame
|
56
|
-
end
|
57
|
-
end
|
58
40
|
end
|
59
41
|
end
|
data/lib/graphql/current.rb
CHANGED
@@ -41,12 +41,17 @@ module GraphQL
|
|
41
41
|
# @see GraphQL::Field#path for a string identifying this field
|
42
42
|
# @return [GraphQL::Field, nil] The currently-running field, if there is one.
|
43
43
|
def self.field
|
44
|
-
|
44
|
+
Fiber[:__graphql_runtime_info]&.values&.first&.current_field
|
45
45
|
end
|
46
46
|
|
47
47
|
# @return [Class, nil] The currently-running {Dataloader::Source} class, if there is one.
|
48
48
|
def self.dataloader_source_class
|
49
49
|
Fiber[:__graphql_current_dataloader_source]&.class
|
50
50
|
end
|
51
|
+
|
52
|
+
# @return [GraphQL::Dataloader::Source, nil] The currently-running source, if there is one
|
53
|
+
def self.dataloader_source
|
54
|
+
Fiber[:__graphql_current_dataloader_source]
|
55
|
+
end
|
51
56
|
end
|
52
57
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "./installable"
|
3
|
+
module Graphql
|
4
|
+
class Dashboard < Rails::Engine
|
5
|
+
module DetailedTraces
|
6
|
+
class TracesController < Graphql::Dashboard::ApplicationController
|
7
|
+
include Installable
|
8
|
+
|
9
|
+
def index
|
10
|
+
@last = params[:last]&.to_i || 50
|
11
|
+
@before = params[:before]&.to_i
|
12
|
+
@traces = schema_class.detailed_trace.traces(last: @last, before: @before)
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
trace = schema_class.detailed_trace.find_trace(params[:id].to_i)
|
17
|
+
send_data(trace.trace_data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def destroy
|
21
|
+
schema_class.detailed_trace.delete_trace(params[:id])
|
22
|
+
flash[:success] = "Trace deleted."
|
23
|
+
head :no_content
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_all
|
27
|
+
schema_class.detailed_trace.delete_all_traces
|
28
|
+
flash[:success] = "Deleted all traces."
|
29
|
+
head :no_content
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def feature_installed?
|
35
|
+
!!schema_class.detailed_trace
|
36
|
+
end
|
37
|
+
|
38
|
+
INSTALLABLE_COMPONENT_HEADER_HTML = "Detailed traces aren't installed yet."
|
39
|
+
INSTALLABLE_COMPONENT_MESSAGE_HTML = <<~HTML.html_safe
|
40
|
+
GraphQL-Ruby can instrument production traffic and save tracing artifacts here for later review.
|
41
|
+
<br>
|
42
|
+
Read more in <a href="https://graphql-ruby.org/queries/tracing#detailed-traces">the detailed tracing docs</a>.
|
43
|
+
HTML
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Graphql
|
3
|
+
class Dashboard < Rails::Engine
|
4
|
+
module Installable
|
5
|
+
def self.included(child_module)
|
6
|
+
child_module.before_action(:check_installed)
|
7
|
+
end
|
8
|
+
|
9
|
+
def feature_installed?
|
10
|
+
raise "Implement #{self.class}#feature_installed? to check whether this should render `not_installed` or not."
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_installed
|
14
|
+
if !feature_installed?
|
15
|
+
@component_header_html = self.class::INSTALLABLE_COMPONENT_HEADER_HTML
|
16
|
+
@component_message_html = self.class::INSTALLABLE_COMPONENT_MESSAGE_HTML
|
17
|
+
render "graphql/dashboard/not_installed"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|