graphql 2.4.16 → 2.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de438ab024dd0f9529cca84745fb63e84189d7e85eb447cfaba1b34f1d18e14f
4
- data.tar.gz: bbdf79794313f06b060ade4125e90bf66ec70ab243e7a27033ad553d576720f1
3
+ metadata.gz: a82f63cf89ed829ecce70f0440ffa72705b0600433d6c63589b77c75139bf50a
4
+ data.tar.gz: dc821060ecb316ece718cfe00173f2c9fdca6195deb5850cf056b71bcfc85855
5
5
  SHA512:
6
- metadata.gz: d2d1b6a04aadd7133ecf3095cb8440d581e461027ac97b69dd4bba5c1839f796eb68d6b2062665ddd42aa52be26328460a2ef81d82eb66c2f39719b2ee2b986d
7
- data.tar.gz: 2f852d8d9c11339fd0de30badffea53f2b79eaa34484e1e833ff60a899ba2ff617e9b4348729b687cbd02629049bc99812c258d368831017d76e566fb770cc62
6
+ metadata.gz: 81aa380e6405acc499fd9cbefddefa9a658928ff2fbde220fbcf0546012280ce15e4d57578fd288819bfe5b80ad74afdce063411458246a3ea4ad2731ce78acb
7
+ data.tar.gz: 59cfad46873d743dc0a698a628037be3ec6c2b0b8ed0e533204c42a2809327095df05cca019f2457d1ec018f7625f89a513008dd552d935f0e452bc19a6691e2
@@ -39,7 +39,6 @@ module GraphQL
39
39
  multiplex = Execution::Multiplex.new(schema: schema, queries: queries, context: context, max_complexity: max_complexity)
40
40
  trace = multiplex.current_trace
41
41
  Fiber[:__graphql_current_multiplex] = multiplex
42
- trace.begin_execute_multiplex(multiplex)
43
42
  trace.execute_multiplex(multiplex: multiplex) do
44
43
  schema = multiplex.schema
45
44
  queries = multiplex.queries
@@ -156,8 +155,6 @@ module GraphQL
156
155
  }
157
156
  end
158
157
  end
159
- ensure
160
- trace&.end_execute_multiplex(multiplex)
161
158
  end
162
159
  end
163
160
 
data/lib/graphql/query.rb CHANGED
@@ -442,7 +442,6 @@ module GraphQL
442
442
  @warden ||= @schema.warden_class.new(schema: @schema, context: @context)
443
443
  parse_error = nil
444
444
  @document ||= begin
445
- current_trace.begin_parse(query_string)
446
445
  if query_string
447
446
  GraphQL.parse(query_string, trace: self.current_trace, max_tokens: @schema.max_query_string_tokens)
448
447
  end
@@ -450,8 +449,6 @@ module GraphQL
450
449
  parse_error = err
451
450
  @schema.parse_error(err, @context)
452
451
  nil
453
- ensure
454
- current_trace.end_parse(query_string)
455
452
  end
456
453
 
457
454
  @fragments = {}
@@ -34,7 +34,7 @@ module GraphQL
34
34
  GraphQL::StaticValidation::VariableUsagesAreAllowed,
35
35
  GraphQL::StaticValidation::MutationRootExists,
36
36
  GraphQL::StaticValidation::QueryRootExists,
37
- GraphQL::StaticValidation::SubscriptionRootExists,
37
+ GraphQL::StaticValidation::SubscriptionRootExistsAndSingleSubscriptionSelection,
38
38
  GraphQL::StaticValidation::InputObjectNamesAreUnique,
39
39
  GraphQL::StaticValidation::OneOfInputObjectsAreValid,
40
40
  ]
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ module StaticValidation
4
+ class NotSingleSubscriptionError < StaticValidation::Error
5
+ def initialize(message, path: nil, nodes: [])
6
+ super(message, path: path, nodes: nodes)
7
+ end
8
+
9
+ # A hash representation of this Message
10
+ def to_h
11
+ extensions = {
12
+ "code" => code,
13
+ }
14
+
15
+ super.merge({
16
+ "extensions" => extensions
17
+ })
18
+ end
19
+
20
+ def code
21
+ "notSingleSubscription"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ module StaticValidation
4
+ module SubscriptionRootExistsAndSingleSubscriptionSelection
5
+ def on_operation_definition(node, parent)
6
+ if node.operation_type == "subscription"
7
+ if context.types.subscription_root.nil?
8
+ add_error(GraphQL::StaticValidation::SubscriptionRootExistsError.new(
9
+ 'Schema is not configured for subscriptions',
10
+ nodes: node
11
+ ))
12
+ elsif node.selections.size != 1
13
+ add_error(GraphQL::StaticValidation::NotSingleSubscriptionError.new(
14
+ 'A subscription operation may only have one selection',
15
+ nodes: node,
16
+ ))
17
+ else
18
+ super
19
+ end
20
+ else
21
+ super
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -10,6 +10,13 @@ module GraphQL
10
10
  # class MySchema < GraphQL::Schema
11
11
  # trace_with(GraphQL::Tracing::ActiveSupportNotificationsTrace)
12
12
  # end
13
+ #
14
+ # @example Subscribing to GraphQL events with ActiveSupport::Notifications
15
+ # ActiveSupport::Notifications.subscribe(/graphql/) do |event|
16
+ # pp event.name
17
+ # pp event.payload
18
+ # end
19
+ #
13
20
  module ActiveSupportNotificationsTrace
14
21
  include NotificationsTrace
15
22
  def initialize(engine: ActiveSupport::Notifications, **rest)
@@ -22,6 +22,11 @@ module GraphQL
22
22
  # These GraphQL events will show up as 'graphql.execute' spans
23
23
  EXEC_KEYS = ['execute_multiplex', 'execute_query', 'execute_query_lazy'].freeze
24
24
 
25
+ def initialize(...)
26
+ warn "GraphQL::Tracing::AppOptics tracing is deprecated; update to SolarWindsAPM instead, which uses OpenTelemetry."
27
+ super
28
+ end
29
+
25
30
  # During auto-instrumentation this version of AppOpticsTracing is compared
26
31
  # with the version provided in the appoptics_apm gem, so that the newer
27
32
  # version of the class can be used
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
-
3
- require "graphql/tracing/platform_trace"
2
+ require "graphql/tracing/monitor_trace"
4
3
 
5
4
  module GraphQL
6
5
  module Tracing
@@ -10,80 +9,46 @@ module GraphQL
10
9
  # class MySchema < GraphQL::Schema
11
10
  # trace_with GraphQL::Tracing::AppsignalTrace
12
11
  # end
12
+ AppsignalTrace = MonitorTrace.create_module("appsignal")
13
13
  module AppsignalTrace
14
- include PlatformTrace
15
-
16
14
  # @param set_action_name [Boolean] If true, the GraphQL operation name will be used as the transaction name.
17
15
  # This is not advised if you run more than one query per HTTP request, for example, with `graphql-client` or multiplexing.
18
16
  # It can also be specified per-query with `context[:set_appsignal_action_name]`.
19
17
  def initialize(set_action_name: false, **rest)
20
- @set_action_name = set_action_name
18
+ rest[:set_transaction_name] ||= set_action_name
19
+ setup_appsignal_monitor(**rest)
21
20
  super
22
21
  end
23
22
 
24
- # rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time
25
-
26
- {
27
- "lex" => "lex.graphql",
28
- "parse" => "parse.graphql",
29
- "validate" => "validate.graphql",
30
- "analyze_query" => "analyze.graphql",
31
- "analyze_multiplex" => "analyze.graphql",
32
- "execute_multiplex" => "execute.graphql",
33
- "execute_query" => "execute.graphql",
34
- "execute_query_lazy" => "execute.graphql",
35
- }.each do |trace_method, platform_key|
36
- module_eval <<-RUBY, __FILE__, __LINE__
37
- def #{trace_method}(**data)
38
- #{
39
- if trace_method == "execute_query"
40
- <<-RUBY
41
- set_this_txn_name = data[:query].context[:set_appsignal_action_name]
42
- if set_this_txn_name == true || (set_this_txn_name.nil? && @set_action_name)
43
- Appsignal::Transaction.current.set_action(transaction_name(data[:query]))
44
- end
45
- RUBY
46
- end
47
- }
48
-
49
- Appsignal.instrument("#{platform_key}") do
50
- super
23
+ class AppsignalMonitor < MonitorTrace::Monitor
24
+ def instrument(keyword, object)
25
+ if keyword == :execute
26
+ query = object.queries.first
27
+ set_this_txn_name = query.context[:set_appsignal_action_name]
28
+ if set_this_txn_name == true || (set_this_txn_name.nil? && @set_transaction_name)
29
+ Appsignal::Transaction.current.set_action(transaction_name(query))
51
30
  end
52
31
  end
53
- RUBY
54
- end
55
-
56
- # rubocop:enable Development/NoEvalCop
57
-
58
- def platform_execute_field(platform_key)
59
- Appsignal.instrument(platform_key) do
60
- yield
32
+ Appsignal.instrument(name_for(keyword, object)) do
33
+ yield
34
+ end
61
35
  end
62
- end
63
36
 
64
- def platform_authorized(platform_key)
65
- Appsignal.instrument(platform_key) do
66
- yield
67
- end
68
- end
37
+ include MonitorTrace::Monitor::GraphQLSuffixNames
38
+ class Event < GraphQL::Tracing::MonitorTrace::Monitor::Event
39
+ def start
40
+ Appsignal::Transaction.current.start_event
41
+ end
69
42
 
70
- def platform_resolve_type(platform_key)
71
- Appsignal.instrument(platform_key) do
72
- yield
43
+ def finish
44
+ Appsignal::Transaction.current.finish_event(
45
+ @monitor.name_for(@keyword, @object),
46
+ "",
47
+ ""
48
+ )
49
+ end
73
50
  end
74
51
  end
75
-
76
- def platform_field_key(field)
77
- "#{field.owner.graphql_name}.#{field.graphql_name}.graphql"
78
- end
79
-
80
- def platform_authorized_key(type)
81
- "#{type.graphql_name}.authorized.graphql"
82
- end
83
-
84
- def platform_resolve_type_key(type)
85
- "#{type.graphql_name}.resolve_type.graphql"
86
- end
87
52
  end
88
53
  end
89
54
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
-
3
- require "graphql/tracing/platform_trace"
2
+ require "graphql/tracing/monitor_trace"
4
3
 
5
4
  module GraphQL
6
5
  module Tracing
@@ -9,186 +8,64 @@ module GraphQL
9
8
  # class MySchema < GraphQL::Schema
10
9
  # trace_with GraphQL::Tracing::DataDogTrace
11
10
  # end
11
+ # @example Skipping `resolve_type` and `authorized` events
12
+ # trace_with GraphQL::Tracing::DataDogTrace, trace_authorized: false, trace_resolve_type: false
13
+ DataDogTrace = MonitorTrace.create_module("datadog")
12
14
  module DataDogTrace
13
- # @param tracer [#trace] Deprecated
14
- # @param analytics_enabled [Boolean] Deprecated
15
- # @param analytics_sample_rate [Float] Deprecated
16
- def initialize(tracer: nil, analytics_enabled: false, analytics_sample_rate: 1.0, service: nil, **rest)
17
- if tracer.nil?
18
- tracer = defined?(Datadog::Tracing) ? Datadog::Tracing : Datadog.tracer
15
+ class DatadogMonitor < MonitorTrace::Monitor
16
+ def initialize(set_transaction_name:, service: nil, tracer: nil, **_rest)
17
+ super
18
+ if tracer.nil?
19
+ tracer = defined?(Datadog::Tracing) ? Datadog::Tracing : Datadog.tracer
20
+ end
21
+ @tracer = tracer
22
+ @service_name = service
23
+ @has_prepare_span = @trace.respond_to?(:prepare_span)
19
24
  end
20
- @tracer = tracer
21
-
22
- @analytics_enabled = analytics_enabled
23
- @analytics_sample_rate = analytics_sample_rate
24
-
25
- @service_name = service
26
- @has_prepare_span = respond_to?(:prepare_span)
27
- super
28
- end
29
-
30
- # rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time
31
25
 
32
- {
33
- 'lex' => 'lex.graphql',
34
- 'parse' => 'parse.graphql',
35
- 'validate' => 'validate.graphql',
36
- 'analyze_query' => 'analyze.graphql',
37
- 'analyze_multiplex' => 'analyze.graphql',
38
- 'execute_multiplex' => 'execute.graphql',
39
- 'execute_query' => 'execute.graphql',
40
- 'execute_query_lazy' => 'execute.graphql',
41
- }.each do |trace_method, trace_key|
42
- module_eval <<-RUBY, __FILE__, __LINE__
43
- def #{trace_method}(**data)
44
- @tracer.trace("#{trace_key}", service: @service_name, type: 'custom') do |span|
45
- span.set_tag('component', 'graphql')
46
- span.set_tag('operation', '#{trace_method}')
26
+ attr_reader :tracer, :service_name
47
27
 
48
- #{
49
- if trace_method == 'execute_multiplex'
50
- <<-RUBY
51
- operations = data[:multiplex].queries.map(&:selected_operation_name).join(', ')
52
-
53
- resource = if operations.empty?
54
- first_query = data[:multiplex].queries.first
55
- fallback_transaction_name(first_query && first_query.context)
56
- else
57
- operations
58
- end
59
- span.resource = resource if resource
60
-
61
- # [Deprecated] will be removed in the future
62
- span.set_metric('_dd1.sr.eausr', @analytics_sample_rate) if @analytics_enabled
63
- RUBY
64
- elsif trace_method == 'execute_query'
65
- <<-RUBY
66
- span.set_tag(:selected_operation_name, data[:query].selected_operation_name)
67
- span.set_tag(:selected_operation_type, data[:query].selected_operation.operation_type)
68
- span.set_tag(:query_string, data[:query].query_string)
69
- RUBY
70
- end
71
- }
72
- if @has_prepare_span
73
- prepare_span("#{trace_method.sub("platform_", "")}", data, span)
28
+ def instrument(keyword, object)
29
+ trace_key = name_for(keyword, object)
30
+ @tracer.trace(trace_key, service: @service_name, type: 'custom') do |span|
31
+ span.set_tag('component', 'graphql')
32
+ op_name = keyword.respond_to?(:name) ? keyword.name : keyword.to_s
33
+ span.set_tag('operation', op_name)
34
+
35
+ if keyword == :execute
36
+ operations = object.queries.map(&:selected_operation_name).join(', ')
37
+ first_query = object.queries.first
38
+ resource = if operations.empty?
39
+ fallback_transaction_name(first_query && first_query.context)
40
+ else
41
+ operations
74
42
  end
75
- super
76
- end
77
- end
78
- RUBY
79
- end
43
+ span.resource = resource if resource
80
44
 
81
- # rubocop:enable Development/NoEvalCop
82
-
83
- def execute_field_span(span_key, query, field, ast_node, arguments, object)
84
- return_type = field.type.unwrap
85
- trace_field = if return_type.kind.scalar? || return_type.kind.enum?
86
- (field.trace.nil? && @trace_scalars) || field.trace
87
- else
88
- true
89
- end
90
- platform_key = if trace_field
91
- @platform_key_cache[DataDogTrace].platform_field_key_cache[field]
92
- else
93
- nil
94
- end
95
- if platform_key && trace_field
96
- @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span|
97
- span.set_tag('component', 'graphql')
98
- span.set_tag('operation', span_key)
45
+ span.set_tag("selected_operation_name", first_query.selected_operation_name)
46
+ span.set_tag("selected_operation_type", first_query.selected_operation&.operation_type)
47
+ span.set_tag("query_string", first_query.query_string)
48
+ end
99
49
 
100
50
  if @has_prepare_span
101
- prepare_span_data = { query: query, field: field, ast_node: ast_node, arguments: arguments, object: object }
102
- prepare_span(span_key, prepare_span_data, span)
51
+ @trace.prepare_span(keyword, object, span)
103
52
  end
104
53
  yield
105
54
  end
106
- else
107
- yield
108
- end
109
- end
110
- def execute_field(query:, field:, ast_node:, arguments:, object:)
111
- execute_field_span("execute_field", query, field, ast_node, arguments, object) do
112
- super(query: query, field: field, ast_node: ast_node, arguments: arguments, object: object)
113
- end
114
- end
115
-
116
- def execute_field_lazy(query:, field:, ast_node:, arguments:, object:)
117
- execute_field_span("execute_field_lazy", query, field, ast_node, arguments, object) do
118
- super(query: query, field: field, ast_node: ast_node, arguments: arguments, object: object)
119
55
  end
120
- end
121
56
 
122
- def authorized(query:, type:, object:)
123
- authorized_span("authorized", object, type, query) do
124
- super(query: query, type: type, object: object)
125
- end
126
- end
127
-
128
- def authorized_span(span_key, object, type, query)
129
- platform_key = @platform_key_cache[DataDogTrace].platform_authorized_key_cache[type]
130
- @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span|
131
- span.set_tag('component', 'graphql')
132
- span.set_tag('operation', span_key)
133
-
134
- if @has_prepare_span
135
- prepare_span(span_key, {object: object, type: type, query: query}, span)
57
+ include MonitorTrace::Monitor::GraphQLSuffixNames
58
+ class Event < MonitorTrace::Monitor::Event
59
+ def start
60
+ name = @monitor.name_for(keyword, object)
61
+ @dd_span = @monitor.tracer.trace(name, service: @monitor.service_name, type: 'custom')
136
62
  end
137
- yield
138
- end
139
- end
140
-
141
- def authorized_lazy(object:, type:, query:)
142
- authorized_span("authorized_lazy", object, type, query) do
143
- super(query: query, type: type, object: object)
144
- end
145
- end
146
-
147
- def resolve_type(object:, type:, query:)
148
- resolve_type_span("resolve_type", object, type, query) do
149
- super(object: object, query: query, type: type)
150
- end
151
- end
152
63
 
153
- def resolve_type_lazy(object:, type:, query:)
154
- resolve_type_span("resolve_type_lazy", object, type, query) do
155
- super(object: object, query: query, type: type)
156
- end
157
- end
158
-
159
- def resolve_type_span(span_key, object, type, query)
160
- platform_key = @platform_key_cache[DataDogTrace].platform_resolve_type_key_cache[type]
161
- @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span|
162
- span.set_tag('component', 'graphql')
163
- span.set_tag('operation', span_key)
164
-
165
- if @has_prepare_span
166
- prepare_span(span_key, {object: object, type: type, query: query}, span)
64
+ def finish
65
+ @dd_span.finish
167
66
  end
168
- yield
169
67
  end
170
68
  end
171
-
172
- include PlatformTrace
173
-
174
- # Implement this method in a subclass to apply custom tags to datadog spans
175
- # @param key [String] The event being traced
176
- # @param data [Hash] The runtime data for this event (@see GraphQL::Tracing for keys for each event)
177
- # @param span [Datadog::Tracing::SpanOperation] The datadog span for this event
178
- # def prepare_span(key, data, span)
179
- # end
180
-
181
- def platform_field_key(field)
182
- field.path
183
- end
184
-
185
- def platform_authorized_key(type)
186
- "#{type.graphql_name}.authorized"
187
- end
188
-
189
- def platform_resolve_type_key(type)
190
- "#{type.graphql_name}.resolve_type"
191
- end
192
69
  end
193
70
  end
194
71
  end