graphql 2.1.15 → 2.2.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.

Potentially problematic release.


This version of graphql might be problematic. Click here for more details.

Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/dataloader/async_dataloader.rb +88 -0
  3. data/lib/graphql/dataloader/source.rb +5 -8
  4. data/lib/graphql/dataloader.rb +35 -21
  5. data/lib/graphql/language/lexer.rb +271 -177
  6. data/lib/graphql/language/nodes.rb +72 -57
  7. data/lib/graphql/language/parser.rb +686 -1986
  8. data/lib/graphql/language/printer.rb +16 -12
  9. data/lib/graphql/language/static_visitor.rb +33 -37
  10. data/lib/graphql/language/visitor.rb +55 -59
  11. data/lib/graphql/schema/argument.rb +5 -3
  12. data/lib/graphql/schema/build_from_definition.rb +7 -8
  13. data/lib/graphql/schema/directive.rb +1 -1
  14. data/lib/graphql/schema/enum_value.rb +1 -1
  15. data/lib/graphql/schema/field.rb +1 -1
  16. data/lib/graphql/schema/input_object.rb +6 -8
  17. data/lib/graphql/schema/interface.rb +2 -6
  18. data/lib/graphql/schema/member/has_directives.rb +1 -1
  19. data/lib/graphql/schema/member/has_fields.rb +1 -1
  20. data/lib/graphql/schema/member/has_interfaces.rb +1 -1
  21. data/lib/graphql/schema/member/scoped.rb +1 -1
  22. data/lib/graphql/schema/member/type_system_helpers.rb +1 -1
  23. data/lib/graphql/schema.rb +6 -5
  24. data/lib/graphql/testing/helpers.rb +125 -0
  25. data/lib/graphql/testing.rb +2 -0
  26. data/lib/graphql/tracing/appoptics_trace.rb +0 -4
  27. data/lib/graphql/tracing/appsignal_trace.rb +0 -4
  28. data/lib/graphql/tracing/data_dog_trace.rb +34 -25
  29. data/lib/graphql/tracing/data_dog_tracing.rb +21 -7
  30. data/lib/graphql/tracing/notifications_trace.rb +0 -4
  31. data/lib/graphql/tracing/platform_trace.rb +0 -5
  32. data/lib/graphql/tracing/prometheus_trace.rb +0 -4
  33. data/lib/graphql/tracing/scout_trace.rb +0 -3
  34. data/lib/graphql/tracing/statsd_trace.rb +0 -4
  35. data/lib/graphql/tracing/trace.rb +1 -0
  36. data/lib/graphql/types/relay/connection_behaviors.rb +1 -1
  37. data/lib/graphql/types/relay/edge_behaviors.rb +1 -1
  38. data/lib/graphql/version.rb +1 -1
  39. data/lib/graphql.rb +1 -0
  40. metadata +21 -19
  41. data/lib/graphql/language/parser.y +0 -560
@@ -3,25 +3,25 @@
3
3
  module GraphQL
4
4
  module Tracing
5
5
  module DataDogTrace
6
- # @param tracer [#trace] Deprecated
7
6
  # @param analytics_enabled [Boolean] Deprecated
8
7
  # @param analytics_sample_rate [Float] Deprecated
9
- def initialize(tracer: nil, analytics_enabled: false, analytics_sample_rate: 1.0, service: nil, **rest)
8
+ def initialize(tracer: nil, analytics_enabled: false, analytics_sample_rate: 1.0, service: "ruby-graphql", **rest)
10
9
  if tracer.nil?
11
10
  tracer = defined?(Datadog::Tracing) ? Datadog::Tracing : Datadog.tracer
12
11
  end
13
12
  @tracer = tracer
14
13
 
15
- @analytics_enabled = analytics_enabled
16
- @analytics_sample_rate = analytics_sample_rate
14
+ analytics_available = defined?(Datadog::Contrib::Analytics) \
15
+ && Datadog::Contrib::Analytics.respond_to?(:enabled?) \
16
+ && Datadog::Contrib::Analytics.respond_to?(:set_sample_rate)
17
17
 
18
+ @analytics_enabled = analytics_available && Datadog::Contrib::Analytics.enabled?(analytics_enabled)
19
+ @analytics_sample_rate = analytics_sample_rate
18
20
  @service_name = service
19
21
  @has_prepare_span = respond_to?(:prepare_span)
20
22
  super
21
23
  end
22
24
 
23
- # rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time
24
-
25
25
  {
26
26
  'lex' => 'lex.graphql',
27
27
  'parse' => 'parse.graphql',
@@ -34,9 +34,12 @@ module GraphQL
34
34
  }.each do |trace_method, trace_key|
35
35
  module_eval <<-RUBY, __FILE__, __LINE__
36
36
  def #{trace_method}(**data)
37
- @tracer.trace("#{trace_key}", service: @service_name, type: 'custom') do |span|
38
- span.set_tag('component', 'graphql')
39
- span.set_tag('operation', '#{trace_method}')
37
+ @tracer.trace("#{trace_key}", service: @service_name) do |span|
38
+ span.span_type = 'custom'
39
+ if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0
40
+ span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql')
41
+ span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, '#{trace_method}')
42
+ end
40
43
 
41
44
  #{
42
45
  if trace_method == 'execute_multiplex'
@@ -51,8 +54,10 @@ module GraphQL
51
54
  end
52
55
  span.resource = resource if resource
53
56
 
54
- # [Deprecated] will be removed in the future
55
- span.set_metric('_dd1.sr.eausr', @analytics_sample_rate) if @analytics_enabled
57
+ # For top span of query, set the analytics sample rate tag, if available.
58
+ if @analytics_enabled
59
+ Datadog::Contrib::Analytics.set_sample_rate(span, @analytics_sample_rate)
60
+ end
56
61
  RUBY
57
62
  elsif trace_method == 'execute_query'
58
63
  <<-RUBY
@@ -71,8 +76,6 @@ module GraphQL
71
76
  RUBY
72
77
  end
73
78
 
74
- # rubocop:enable Development/NoEvalCop
75
-
76
79
  def execute_field_span(span_key, query, field, ast_node, arguments, object)
77
80
  return_type = field.type.unwrap
78
81
  trace_field = if return_type.kind.scalar? || return_type.kind.enum?
@@ -86,10 +89,12 @@ module GraphQL
86
89
  nil
87
90
  end
88
91
  if platform_key && trace_field
89
- @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span|
90
- span.set_tag('component', 'graphql')
91
- span.set_tag('operation', span_key)
92
-
92
+ @tracer.trace(platform_key, service: @service_name) do |span|
93
+ span.span_type = 'custom'
94
+ if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0
95
+ span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql')
96
+ span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, span_key)
97
+ end
93
98
  if @has_prepare_span
94
99
  prepare_span_data = { query: query, field: field, ast_node: ast_node, arguments: arguments, object: object }
95
100
  prepare_span(span_key, prepare_span_data, span)
@@ -120,10 +125,12 @@ module GraphQL
120
125
 
121
126
  def authorized_span(span_key, object, type, query)
122
127
  platform_key = @platform_key_cache[DataDogTrace].platform_authorized_key_cache[type]
123
- @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span|
124
- span.set_tag('component', 'graphql')
125
- span.set_tag('operation', span_key)
126
-
128
+ @tracer.trace(platform_key, service: @service_name) do |span|
129
+ span.span_type = 'custom'
130
+ if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0
131
+ span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql')
132
+ span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, span_key)
133
+ end
127
134
  if @has_prepare_span
128
135
  prepare_span(span_key, {object: object, type: type, query: query}, span)
129
136
  end
@@ -151,10 +158,12 @@ module GraphQL
151
158
 
152
159
  def resolve_type_span(span_key, object, type, query)
153
160
  platform_key = @platform_key_cache[DataDogTrace].platform_resolve_type_key_cache[type]
154
- @tracer.trace(platform_key, service: @service_name, type: 'custom') do |span|
155
- span.set_tag('component', 'graphql')
156
- span.set_tag('operation', span_key)
157
-
161
+ @tracer.trace(platform_key, service: @service_name) do |span|
162
+ span.span_type = 'custom'
163
+ if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0
164
+ span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql')
165
+ span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, span_key)
166
+ end
158
167
  if @has_prepare_span
159
168
  prepare_span(span_key, {object: object, type: type, query: query}, span)
160
169
  end
@@ -15,9 +15,12 @@ module GraphQL
15
15
  }
16
16
 
17
17
  def platform_trace(platform_key, key, data)
18
- tracer.trace(platform_key, service: options[:service], type: 'custom') do |span|
19
- span.set_tag('component', 'graphql')
20
- span.set_tag('operation', key)
18
+ tracer.trace(platform_key, service: service_name) do |span|
19
+ span.span_type = 'custom'
20
+ if defined?(Datadog::Tracing::Metadata::Ext) # Introduced in ddtrace 1.0
21
+ span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, 'graphql')
22
+ span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, key)
23
+ end
21
24
 
22
25
  if key == 'execute_multiplex'
23
26
  operations = data[:multiplex].queries.map(&:selected_operation_name).join(', ')
@@ -30,8 +33,10 @@ module GraphQL
30
33
  end
31
34
  span.resource = resource if resource
32
35
 
33
- # [Deprecated] will be removed in the future
34
- span.set_metric('_dd1.sr.eausr', analytics_sample_rate) if analytics_enabled?
36
+ # For top span of query, set the analytics sample rate tag, if available.
37
+ if analytics_enabled?
38
+ Datadog::Contrib::Analytics.set_sample_rate(span, analytics_sample_rate)
39
+ end
35
40
  end
36
41
 
37
42
  if key == 'execute_query'
@@ -46,6 +51,10 @@ module GraphQL
46
51
  end
47
52
  end
48
53
 
54
+ def service_name
55
+ options.fetch(:service, 'ruby-graphql')
56
+ end
57
+
49
58
  # Implement this method in a subclass to apply custom tags to datadog spans
50
59
  # @param key [String] The event being traced
51
60
  # @param data [Hash] The runtime data for this event (@see GraphQL::Tracing for keys for each event)
@@ -56,13 +65,18 @@ module GraphQL
56
65
  def tracer
57
66
  default_tracer = defined?(Datadog::Tracing) ? Datadog::Tracing : Datadog.tracer
58
67
 
59
- # [Deprecated] options[:tracer] will be removed in the future
60
68
  options.fetch(:tracer, default_tracer)
61
69
  end
62
70
 
71
+ def analytics_available?
72
+ defined?(Datadog::Contrib::Analytics) \
73
+ && Datadog::Contrib::Analytics.respond_to?(:enabled?) \
74
+ && Datadog::Contrib::Analytics.respond_to?(:set_sample_rate)
75
+ end
76
+
63
77
  def analytics_enabled?
64
78
  # [Deprecated] options[:analytics_enabled] will be removed in the future
65
- options.fetch(:analytics_enabled, false)
79
+ analytics_available? && Datadog::Contrib::Analytics.enabled?(options.fetch(:analytics_enabled, false))
66
80
  end
67
81
 
68
82
  def analytics_sample_rate
@@ -16,8 +16,6 @@ module GraphQL
16
16
  super
17
17
  end
18
18
 
19
- # rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time
20
-
21
19
  {
22
20
  "lex" => "lex.graphql",
23
21
  "parse" => "parse.graphql",
@@ -41,8 +39,6 @@ module GraphQL
41
39
  RUBY
42
40
  end
43
41
 
44
- # rubocop:enable Development/NoEvalCop
45
-
46
42
  include PlatformTrace
47
43
  end
48
44
  end
@@ -39,9 +39,6 @@ module GraphQL
39
39
  include(BaseKeyCache)
40
40
  }
41
41
  child_class.const_set(:KeyCache, key_methods_class)
42
-
43
- # rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time
44
-
45
42
  [:execute_field, :execute_field_lazy].each do |field_trace_method|
46
43
  if !child_class.method_defined?(field_trace_method)
47
44
  child_class.module_eval <<-RUBY, __FILE__, __LINE__
@@ -94,8 +91,6 @@ module GraphQL
94
91
  end
95
92
  RUBY
96
93
  end
97
-
98
- # rubocop:enable Development/NoEvalCop
99
94
  end
100
95
  end
101
96
 
@@ -13,8 +13,6 @@ module GraphQL
13
13
  super(**rest)
14
14
  end
15
15
 
16
- # rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time
17
-
18
16
  {
19
17
  'lex' => "graphql.lex",
20
18
  'parse' => "graphql.parse",
@@ -32,8 +30,6 @@ module GraphQL
32
30
  RUBY
33
31
  end
34
32
 
35
- # rubocop:enable Development/NoEvalCop
36
-
37
33
  def platform_execute_field(platform_key, &block)
38
34
  instrument_execution(platform_key, "execute_field", &block)
39
35
  end
@@ -16,8 +16,6 @@ module GraphQL
16
16
  super
17
17
  end
18
18
 
19
- # rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time
20
-
21
19
  {
22
20
  "lex" => "lex.graphql",
23
21
  "parse" => "parse.graphql",
@@ -47,7 +45,6 @@ module GraphQL
47
45
  end
48
46
  RUBY
49
47
  end
50
- # rubocop:enable Development/NoEvalCop
51
48
 
52
49
  def platform_execute_field(platform_key, &block)
53
50
  self.class.instrument("GraphQL", platform_key, INSTRUMENT_OPTS, &block)
@@ -11,8 +11,6 @@ module GraphQL
11
11
  super(**rest)
12
12
  end
13
13
 
14
- # rubocop:disable Development/NoEvalCop This eval takes static inputs at load-time
15
-
16
14
  {
17
15
  'lex' => "graphql.lex",
18
16
  'parse' => "graphql.parse",
@@ -32,8 +30,6 @@ module GraphQL
32
30
  RUBY
33
31
  end
34
32
 
35
- # rubocop:enable Development/NoEvalCop
36
-
37
33
  def platform_execute_field(platform_key, &block)
38
34
  @statsd.time(platform_key, &block)
39
35
  end
@@ -15,6 +15,7 @@ module GraphQL
15
15
  @query = query
16
16
  end
17
17
 
18
+ # The Ruby parser doesn't call this method (`graphql/c_parser` does.)
18
19
  def lex(query_string:)
19
20
  yield
20
21
  end
@@ -13,7 +13,7 @@ module GraphQL
13
13
  child_class.node_nullable(true)
14
14
  child_class.edges_nullable(true)
15
15
  child_class.edge_nullable(true)
16
- child_class.module_exec {
16
+ child_class.module_eval {
17
17
  self.edge_type = nil
18
18
  self.node_type = nil
19
19
  self.edge_class = nil
@@ -8,7 +8,7 @@ module GraphQL
8
8
  child_class.description("An edge in a connection.")
9
9
  child_class.field(:cursor, String, null: false, description: "A cursor for use in pagination.")
10
10
  child_class.extend(ClassMethods)
11
- child_class.class_exec { self.node_type = nil }
11
+ child_class.class_eval { self.node_type = nil }
12
12
  child_class.node_nullable(true)
13
13
  end
14
14
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "2.1.15"
3
+ VERSION = "2.2.0"
4
4
  end
data/lib/graphql.rb CHANGED
@@ -121,3 +121,4 @@ require "graphql/unauthorized_error"
121
121
  require "graphql/unauthorized_field_error"
122
122
  require "graphql/load_application_object_failed_error"
123
123
  require "graphql/deprecation"
124
+ require "graphql/testing"
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.1.15
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-12 00:00:00.000000000 Z
11
+ date: 2023-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: racc
@@ -70,44 +70,44 @@ dependencies:
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 5.9.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 5.9.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: minitest-focus
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '1.1'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '1.1'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: minitest-reporters
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '1.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '1.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -309,6 +309,7 @@ files:
309
309
  - lib/graphql/backtrace/tracer.rb
310
310
  - lib/graphql/coercion_error.rb
311
311
  - lib/graphql/dataloader.rb
312
+ - lib/graphql/dataloader/async_dataloader.rb
312
313
  - lib/graphql/dataloader/null_dataloader.rb
313
314
  - lib/graphql/dataloader/request.rb
314
315
  - lib/graphql/dataloader/request_all.rb
@@ -360,7 +361,6 @@ files:
360
361
  - lib/graphql/language/lexer.rb
361
362
  - lib/graphql/language/nodes.rb
362
363
  - lib/graphql/language/parser.rb
363
- - lib/graphql/language/parser.y
364
364
  - lib/graphql/language/printer.rb
365
365
  - lib/graphql/language/sanitized_printer.rb
366
366
  - lib/graphql/language/static_visitor.rb
@@ -553,6 +553,8 @@ files:
553
553
  - lib/graphql/subscriptions/event.rb
554
554
  - lib/graphql/subscriptions/instrumentation.rb
555
555
  - lib/graphql/subscriptions/serialize.rb
556
+ - lib/graphql/testing.rb
557
+ - lib/graphql/testing/helpers.rb
556
558
  - lib/graphql/tracing.rb
557
559
  - lib/graphql/tracing/active_support_notifications_trace.rb
558
560
  - lib/graphql/tracing/active_support_notifications_tracing.rb
@@ -614,7 +616,7 @@ metadata:
614
616
  source_code_uri: https://github.com/rmosolgo/graphql-ruby
615
617
  bug_tracker_uri: https://github.com/rmosolgo/graphql-ruby/issues
616
618
  mailing_list_uri: https://tinyletter.com/graphql-ruby
617
- post_install_message:
619
+ post_install_message:
618
620
  rdoc_options: []
619
621
  require_paths:
620
622
  - lib
@@ -629,8 +631,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
629
631
  - !ruby/object:Gem::Version
630
632
  version: '0'
631
633
  requirements: []
632
- rubygems_version: 3.1.6
633
- signing_key:
634
+ rubygems_version: 3.4.10
635
+ signing_key:
634
636
  specification_version: 4
635
637
  summary: A GraphQL language and runtime for Ruby
636
638
  test_files: []