graphql 1.13.13 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
  3. data/lib/graphql/analysis/ast/query_depth.rb +0 -1
  4. data/lib/graphql/analysis/ast/visitor.rb +1 -1
  5. data/lib/graphql/analysis/ast.rb +0 -10
  6. data/lib/graphql/analysis.rb +0 -7
  7. data/lib/graphql/backtrace/table.rb +0 -18
  8. data/lib/graphql/backtrace/tracer.rb +1 -2
  9. data/lib/graphql/backtrace.rb +2 -8
  10. data/lib/graphql/dig.rb +1 -1
  11. data/lib/graphql/execution/errors.rb +1 -9
  12. data/lib/graphql/execution/interpreter/runtime.rb +2 -9
  13. data/lib/graphql/execution/interpreter.rb +0 -22
  14. data/lib/graphql/execution/lazy.rb +1 -1
  15. data/lib/graphql/execution/lookahead.rb +6 -13
  16. data/lib/graphql/execution/multiplex.rb +50 -107
  17. data/lib/graphql/execution.rb +11 -3
  18. data/lib/graphql/introspection/dynamic_fields.rb +3 -8
  19. data/lib/graphql/introspection/entry_points.rb +2 -15
  20. data/lib/graphql/language/document_from_schema_definition.rb +0 -17
  21. data/lib/graphql/pagination/connections.rb +2 -28
  22. data/lib/graphql/query/context.rb +1 -185
  23. data/lib/graphql/query/literal_input.rb +8 -13
  24. data/lib/graphql/query/validation_pipeline.rb +8 -37
  25. data/lib/graphql/query/variables.rb +22 -18
  26. data/lib/graphql/query.rb +5 -35
  27. data/lib/graphql/railtie.rb +0 -104
  28. data/lib/graphql/relay/range_add.rb +0 -4
  29. data/lib/graphql/relay.rb +0 -15
  30. data/lib/graphql/schema/addition.rb +1 -8
  31. data/lib/graphql/schema/argument.rb +1 -25
  32. data/lib/graphql/schema/build_from_definition.rb +0 -1
  33. data/lib/graphql/schema/directive.rb +0 -21
  34. data/lib/graphql/schema/enum.rb +1 -18
  35. data/lib/graphql/schema/enum_value.rb +0 -22
  36. data/lib/graphql/schema/field.rb +2 -183
  37. data/lib/graphql/schema/input_object.rb +9 -56
  38. data/lib/graphql/schema/interface.rb +0 -25
  39. data/lib/graphql/schema/introspection_system.rb +3 -8
  40. data/lib/graphql/schema/late_bound_type.rb +2 -2
  41. data/lib/graphql/schema/list.rb +0 -6
  42. data/lib/graphql/schema/loader.rb +0 -1
  43. data/lib/graphql/schema/member/base_dsl_methods.rb +0 -5
  44. data/lib/graphql/schema/member/build_type.rb +4 -6
  45. data/lib/graphql/schema/member/has_arguments.rb +14 -18
  46. data/lib/graphql/schema/member/has_fields.rb +2 -2
  47. data/lib/graphql/schema/member/has_interfaces.rb +0 -2
  48. data/lib/graphql/schema/member.rb +0 -6
  49. data/lib/graphql/schema/mutation.rb +0 -9
  50. data/lib/graphql/schema/non_null.rb +1 -7
  51. data/lib/graphql/schema/object.rb +0 -40
  52. data/lib/graphql/schema/relay_classic_mutation.rb +17 -28
  53. data/lib/graphql/schema/scalar.rb +0 -15
  54. data/lib/graphql/schema/union.rb +0 -16
  55. data/lib/graphql/schema/warden.rb +1 -1
  56. data/lib/graphql/schema/wrapper.rb +0 -5
  57. data/lib/graphql/schema.rb +106 -945
  58. data/lib/graphql/static_validation/base_visitor.rb +4 -21
  59. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
  60. data/lib/graphql/static_validation/validator.rb +2 -24
  61. data/lib/graphql/static_validation.rb +0 -2
  62. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
  63. data/lib/graphql/subscriptions/event.rb +1 -1
  64. data/lib/graphql/subscriptions/instrumentation.rb +0 -51
  65. data/lib/graphql/subscriptions.rb +4 -13
  66. data/lib/graphql/tracing/data_dog_tracing.rb +1 -16
  67. data/lib/graphql/tracing/platform_tracing.rb +4 -31
  68. data/lib/graphql/tracing.rb +0 -2
  69. data/lib/graphql/types/relay/connection_behaviors.rb +2 -6
  70. data/lib/graphql/types/relay/default_relay.rb +0 -10
  71. data/lib/graphql/types/relay/node_behaviors.rb +5 -1
  72. data/lib/graphql/types/relay.rb +0 -2
  73. data/lib/graphql/version.rb +1 -1
  74. data/lib/graphql.rb +1 -65
  75. metadata +6 -132
  76. data/lib/graphql/analysis/analyze_query.rb +0 -98
  77. data/lib/graphql/analysis/field_usage.rb +0 -45
  78. data/lib/graphql/analysis/max_query_complexity.rb +0 -26
  79. data/lib/graphql/analysis/max_query_depth.rb +0 -26
  80. data/lib/graphql/analysis/query_complexity.rb +0 -88
  81. data/lib/graphql/analysis/query_depth.rb +0 -43
  82. data/lib/graphql/analysis/reducer_state.rb +0 -48
  83. data/lib/graphql/argument.rb +0 -131
  84. data/lib/graphql/authorization.rb +0 -82
  85. data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
  86. data/lib/graphql/backwards_compatibility.rb +0 -61
  87. data/lib/graphql/base_type.rb +0 -232
  88. data/lib/graphql/boolean_type.rb +0 -2
  89. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
  90. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
  91. data/lib/graphql/compatibility/execution_specification.rb +0 -436
  92. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
  93. data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
  94. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
  95. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
  96. data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
  97. data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
  98. data/lib/graphql/compatibility.rb +0 -5
  99. data/lib/graphql/define/assign_argument.rb +0 -12
  100. data/lib/graphql/define/assign_connection.rb +0 -13
  101. data/lib/graphql/define/assign_enum_value.rb +0 -18
  102. data/lib/graphql/define/assign_global_id_field.rb +0 -11
  103. data/lib/graphql/define/assign_mutation_function.rb +0 -34
  104. data/lib/graphql/define/assign_object_field.rb +0 -42
  105. data/lib/graphql/define/defined_object_proxy.rb +0 -53
  106. data/lib/graphql/define/instance_definable.rb +0 -255
  107. data/lib/graphql/define/no_definition_error.rb +0 -7
  108. data/lib/graphql/define/non_null_with_bang.rb +0 -16
  109. data/lib/graphql/define/type_definer.rb +0 -31
  110. data/lib/graphql/define.rb +0 -31
  111. data/lib/graphql/deprecated_dsl.rb +0 -55
  112. data/lib/graphql/directive/deprecated_directive.rb +0 -2
  113. data/lib/graphql/directive/include_directive.rb +0 -2
  114. data/lib/graphql/directive/skip_directive.rb +0 -2
  115. data/lib/graphql/directive.rb +0 -107
  116. data/lib/graphql/enum_type.rb +0 -133
  117. data/lib/graphql/execution/execute.rb +0 -333
  118. data/lib/graphql/execution/flatten.rb +0 -40
  119. data/lib/graphql/execution/typecast.rb +0 -50
  120. data/lib/graphql/field/resolve.rb +0 -59
  121. data/lib/graphql/field.rb +0 -226
  122. data/lib/graphql/float_type.rb +0 -2
  123. data/lib/graphql/function.rb +0 -128
  124. data/lib/graphql/id_type.rb +0 -2
  125. data/lib/graphql/input_object_type.rb +0 -138
  126. data/lib/graphql/int_type.rb +0 -2
  127. data/lib/graphql/interface_type.rb +0 -72
  128. data/lib/graphql/internal_representation/document.rb +0 -27
  129. data/lib/graphql/internal_representation/node.rb +0 -206
  130. data/lib/graphql/internal_representation/print.rb +0 -51
  131. data/lib/graphql/internal_representation/rewrite.rb +0 -184
  132. data/lib/graphql/internal_representation/scope.rb +0 -88
  133. data/lib/graphql/internal_representation/visit.rb +0 -36
  134. data/lib/graphql/internal_representation.rb +0 -7
  135. data/lib/graphql/list_type.rb +0 -80
  136. data/lib/graphql/non_null_type.rb +0 -71
  137. data/lib/graphql/object_type.rb +0 -130
  138. data/lib/graphql/query/arguments.rb +0 -189
  139. data/lib/graphql/query/arguments_cache.rb +0 -24
  140. data/lib/graphql/query/executor.rb +0 -52
  141. data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
  142. data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
  143. data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
  144. data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
  145. data/lib/graphql/query/serial_execution.rb +0 -40
  146. data/lib/graphql/relay/array_connection.rb +0 -83
  147. data/lib/graphql/relay/base_connection.rb +0 -189
  148. data/lib/graphql/relay/connection_instrumentation.rb +0 -54
  149. data/lib/graphql/relay/connection_resolve.rb +0 -43
  150. data/lib/graphql/relay/connection_type.rb +0 -54
  151. data/lib/graphql/relay/edge.rb +0 -27
  152. data/lib/graphql/relay/edge_type.rb +0 -19
  153. data/lib/graphql/relay/edges_instrumentation.rb +0 -39
  154. data/lib/graphql/relay/global_id_resolve.rb +0 -17
  155. data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
  156. data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
  157. data/lib/graphql/relay/mutation/resolve.rb +0 -56
  158. data/lib/graphql/relay/mutation/result.rb +0 -38
  159. data/lib/graphql/relay/mutation.rb +0 -106
  160. data/lib/graphql/relay/node.rb +0 -39
  161. data/lib/graphql/relay/page_info.rb +0 -7
  162. data/lib/graphql/relay/relation_connection.rb +0 -188
  163. data/lib/graphql/relay/type_extensions.rb +0 -32
  164. data/lib/graphql/scalar_type.rb +0 -91
  165. data/lib/graphql/schema/catchall_middleware.rb +0 -35
  166. data/lib/graphql/schema/default_parse_error.rb +0 -10
  167. data/lib/graphql/schema/default_type_error.rb +0 -17
  168. data/lib/graphql/schema/member/accepts_definition.rb +0 -164
  169. data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
  170. data/lib/graphql/schema/member/instrumentation.rb +0 -131
  171. data/lib/graphql/schema/middleware_chain.rb +0 -82
  172. data/lib/graphql/schema/possible_types.rb +0 -44
  173. data/lib/graphql/schema/rescue_middleware.rb +0 -60
  174. data/lib/graphql/schema/timeout_middleware.rb +0 -88
  175. data/lib/graphql/schema/traversal.rb +0 -228
  176. data/lib/graphql/schema/validation.rb +0 -313
  177. data/lib/graphql/static_validation/default_visitor.rb +0 -15
  178. data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
  179. data/lib/graphql/string_type.rb +0 -2
  180. data/lib/graphql/subscriptions/subscription_root.rb +0 -76
  181. data/lib/graphql/tracing/opentelemetry_tracing.rb +0 -101
  182. data/lib/graphql/tracing/skylight_tracing.rb +0 -70
  183. data/lib/graphql/types/relay/node_field.rb +0 -24
  184. data/lib/graphql/types/relay/nodes_field.rb +0 -43
  185. data/lib/graphql/union_type.rb +0 -115
  186. data/lib/graphql/upgrader/member.rb +0 -937
  187. data/lib/graphql/upgrader/schema.rb +0 -38
@@ -14,11 +14,6 @@ module GraphQL
14
14
  super(document)
15
15
  end
16
16
 
17
- # This will be overwritten by {InternalRepresentation::Rewrite} if it's included
18
- def rewrite_document
19
- nil
20
- end
21
-
22
17
  attr_reader :context
23
18
 
24
19
  # @return [Array<GraphQL::ObjectType>] Types whose scope we've entered
@@ -32,22 +27,13 @@ module GraphQL
32
27
  # Build a class to visit the AST and perform validation,
33
28
  # or use a pre-built class if rules is `ALL_RULES` or empty.
34
29
  # @param rules [Array<Module, Class>]
35
- # @param rewrite [Boolean] if `false`, don't include rewrite
36
30
  # @return [Class] A class for validating `rules` during visitation
37
- def self.including_rules(rules, rewrite: true)
31
+ def self.including_rules(rules)
38
32
  if rules.empty?
39
- if rewrite
40
- NoValidateVisitor
41
- else
42
- # It's not doing _anything?!?_
43
- BaseVisitor
44
- end
33
+ # It's not doing _anything?!?_
34
+ BaseVisitor
45
35
  elsif rules == ALL_RULES
46
- if rewrite
47
- DefaultVisitor
48
- else
49
- InterpreterVisitor
50
- end
36
+ InterpreterVisitor
51
37
  else
52
38
  visitor_class = Class.new(self) do
53
39
  include(GraphQL::StaticValidation::DefinitionDependencies)
@@ -60,9 +46,6 @@ module GraphQL
60
46
  end
61
47
  end
62
48
 
63
- if rewrite
64
- visitor_class.include(GraphQL::InternalRepresentation::Rewrite)
65
- end
66
49
  visitor_class.include(ContextMethods)
67
50
  visitor_class
68
51
  end
@@ -12,20 +12,20 @@ module GraphQL
12
12
  private
13
13
 
14
14
  LOCATION_MESSAGE_NAMES = {
15
- GraphQL::Directive::QUERY => "queries",
16
- GraphQL::Directive::MUTATION => "mutations",
17
- GraphQL::Directive::SUBSCRIPTION => "subscriptions",
18
- GraphQL::Directive::FIELD => "fields",
19
- GraphQL::Directive::FRAGMENT_DEFINITION => "fragment definitions",
20
- GraphQL::Directive::FRAGMENT_SPREAD => "fragment spreads",
21
- GraphQL::Directive::INLINE_FRAGMENT => "inline fragments",
15
+ GraphQL::Schema::Directive::QUERY => "queries",
16
+ GraphQL::Schema::Directive::MUTATION => "mutations",
17
+ GraphQL::Schema::Directive::SUBSCRIPTION => "subscriptions",
18
+ GraphQL::Schema::Directive::FIELD => "fields",
19
+ GraphQL::Schema::Directive::FRAGMENT_DEFINITION => "fragment definitions",
20
+ GraphQL::Schema::Directive::FRAGMENT_SPREAD => "fragment spreads",
21
+ GraphQL::Schema::Directive::INLINE_FRAGMENT => "inline fragments",
22
22
  }
23
23
 
24
24
  SIMPLE_LOCATIONS = {
25
- Nodes::Field => GraphQL::Directive::FIELD,
26
- Nodes::InlineFragment => GraphQL::Directive::INLINE_FRAGMENT,
27
- Nodes::FragmentSpread => GraphQL::Directive::FRAGMENT_SPREAD,
28
- Nodes::FragmentDefinition => GraphQL::Directive::FRAGMENT_DEFINITION,
25
+ Nodes::Field => GraphQL::Schema::Directive::FIELD,
26
+ Nodes::InlineFragment => GraphQL::Schema::Directive::INLINE_FRAGMENT,
27
+ Nodes::FragmentSpread => GraphQL::Schema::Directive::FRAGMENT_SPREAD,
28
+ Nodes::FragmentDefinition => GraphQL::Schema::Directive::FRAGMENT_DEFINITION,
29
29
  }
30
30
 
31
31
  SIMPLE_LOCATION_NODES = SIMPLE_LOCATIONS.keys
@@ -34,7 +34,7 @@ module GraphQL
34
34
  directive_defn = directives[ast_directive.name]
35
35
  case ast_parent
36
36
  when Nodes::OperationDefinition
37
- required_location = GraphQL::Directive.const_get(ast_parent.operation_type.upcase)
37
+ required_location = GraphQL::Schema::Directive.const_get(ast_parent.operation_type.upcase)
38
38
  assert_includes_location(directive_defn, ast_directive, required_location)
39
39
  when *SIMPLE_LOCATION_NODES
40
40
  required_location = SIMPLE_LOCATIONS[ast_parent.class]
@@ -28,12 +28,11 @@ module GraphQL
28
28
  # @return [Array<Hash>]
29
29
  def validate(query, validate: true, timeout: nil, max_errors: nil)
30
30
  query.trace("validate", { validate: validate, query: query }) do
31
- can_skip_rewrite = query.context.interpreter? && query.schema.using_ast_analysis? && query.schema.is_a?(Class)
32
- errors = if validate == false && can_skip_rewrite
31
+ errors = if validate == false
33
32
  []
34
33
  else
35
34
  rules_to_use = validate ? @rules : []
36
- visitor_class = BaseVisitor.including_rules(rules_to_use, rewrite: !can_skip_rewrite)
35
+ visitor_class = BaseVisitor.including_rules(rules_to_use)
37
36
 
38
37
  context = GraphQL::StaticValidation::ValidationContext.new(query, visitor_class, max_errors)
39
38
 
@@ -42,18 +41,6 @@ module GraphQL
42
41
  # A timeout value of 0 or nil will execute the block without any timeout.
43
42
  Timeout::timeout(timeout) do
44
43
  catch(:too_many_validation_errors) do
45
- # Attach legacy-style rules.
46
- # Only loop through rules if it has legacy-style rules
47
- unless (legacy_rules = rules_to_use - GraphQL::StaticValidation::ALL_RULES).empty?
48
- legacy_rules.each do |rule_class_or_module|
49
- if rule_class_or_module.method_defined?(:validate)
50
- GraphQL::Deprecation.warn "Legacy validator rules will be removed from GraphQL-Ruby 2.0, use a module instead (see the built-in rules: https://github.com/rmosolgo/graphql-ruby/tree/master/lib/graphql/static_validation/rules)"
51
- GraphQL::Deprecation.warn " -> Legacy validator: #{rule_class_or_module}"
52
- rule_class_or_module.new.validate(context)
53
- end
54
- end
55
- end
56
-
57
44
  context.visitor.visit
58
45
  end
59
46
  end
@@ -64,22 +51,13 @@ module GraphQL
64
51
  context.errors
65
52
  end
66
53
 
67
- irep = if errors.empty? && context
68
- # Only return this if there are no errors and validation was actually run
69
- context.visitor.rewrite_document
70
- else
71
- nil
72
- end
73
-
74
54
  {
75
55
  errors: errors,
76
- irep: irep,
77
56
  }
78
57
  end
79
58
  rescue GraphQL::ExecutionError => e
80
59
  {
81
60
  errors: [e],
82
- irep: nil,
83
61
  }
84
62
  end
85
63
 
@@ -7,7 +7,6 @@ require "graphql/static_validation/validation_context"
7
7
  require "graphql/static_validation/validation_timeout_error"
8
8
  require "graphql/static_validation/literal_validator"
9
9
  require "graphql/static_validation/base_visitor"
10
- require "graphql/static_validation/no_validate_visitor"
11
10
 
12
11
  rules_glob = File.expand_path("../static_validation/rules/*.rb", __FILE__)
13
12
  Dir.glob(rules_glob).each do |file|
@@ -15,5 +14,4 @@ Dir.glob(rules_glob).each do |file|
15
14
  end
16
15
 
17
16
  require "graphql/static_validation/all_rules"
18
- require "graphql/static_validation/default_visitor"
19
17
  require "graphql/static_validation/interpreter_visitor"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
3
  class Subscriptions
4
- class DefaultSubscriptionResolveExtension < GraphQL::Subscriptions::SubscriptionRoot::Extension
4
+ class DefaultSubscriptionResolveExtension < GraphQL::Schema::FieldExtension
5
5
  def resolve(context:, object:, arguments:)
6
6
  has_override_implementation = @field.resolver ||
7
7
  object.respond_to?(@field.resolver_method)
@@ -16,6 +16,43 @@ module GraphQL
16
16
  yield(object, arguments)
17
17
  end
18
18
  end
19
+
20
+ def after_resolve(value:, context:, object:, arguments:, **rest)
21
+ if value.is_a?(GraphQL::ExecutionError)
22
+ value
23
+ elsif (events = context.namespace(:subscriptions)[:events])
24
+ # This is the first execution, so gather an Event
25
+ # for the backend to register:
26
+ event = Subscriptions::Event.new(
27
+ name: field.name,
28
+ arguments: arguments_without_field_extras(arguments: arguments),
29
+ context: context,
30
+ field: field,
31
+ )
32
+ events << event
33
+ value
34
+ elsif context.query.subscription_topic == Subscriptions::Event.serialize(
35
+ field.name,
36
+ arguments_without_field_extras(arguments: arguments),
37
+ field,
38
+ scope: (field.subscription_scope ? context[field.subscription_scope] : nil),
39
+ )
40
+ # This is a subscription update. The resolver returned `skip` if it should be skipped,
41
+ # or else it returned an object to resolve the update.
42
+ value
43
+ else
44
+ # This is a subscription update, but this event wasn't triggered.
45
+ context.skip
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def arguments_without_field_extras(arguments:)
52
+ arguments.dup.tap do |event_args|
53
+ field.extras.each { |k| event_args.delete(k) }
54
+ end
55
+ end
19
56
  end
20
57
  end
21
58
  end
@@ -9,7 +9,7 @@ module GraphQL
9
9
  # @return [String] Corresponds to the Subscription root field name
10
10
  attr_reader :name
11
11
 
12
- # @return [GraphQL::Query::Arguments]
12
+ # @return [GraphQL::Execution::Interpreter::Arguments]
13
13
  attr_reader :arguments
14
14
 
15
15
  # @return [GraphQL::Query::Context]
@@ -9,16 +9,6 @@ module GraphQL
9
9
  @schema = schema
10
10
  end
11
11
 
12
- def instrument(type, field)
13
- if type == @schema.subscription.graphql_definition
14
- # This is a root field of `subscription`
15
- subscribing_resolve_proc = SubscriptionRegistrationResolve.new(field.resolve_proc)
16
- field.redefine(resolve: subscribing_resolve_proc)
17
- else
18
- field
19
- end
20
- end
21
-
22
12
  # If needed, prepare to gather events which this query subscribes to
23
13
  def before_query(query)
24
14
  if query.subscription? && !query.subscription_update?
@@ -33,47 +23,6 @@ module GraphQL
33
23
  @schema.subscriptions.write_subscription(query, events)
34
24
  end
35
25
  end
36
-
37
- private
38
-
39
- class SubscriptionRegistrationResolve
40
- def initialize(inner_proc)
41
- @inner_proc = inner_proc
42
- end
43
-
44
- # Wrap the proc with subscription registration logic
45
- def call(obj, args, ctx)
46
- result = nil
47
- if @inner_proc && !@inner_proc.is_a?(GraphQL::Field::Resolve::BuiltInResolve)
48
- result = @inner_proc.call(obj, args, ctx)
49
- end
50
-
51
- events = ctx.namespace(:subscriptions)[:events]
52
-
53
- if events
54
- # This is the first execution, so gather an Event
55
- # for the backend to register:
56
- events << Subscriptions::Event.new(
57
- name: ctx.field.name,
58
- arguments: args,
59
- context: ctx,
60
- )
61
- result
62
- elsif ctx.irep_node.subscription_topic == ctx.query.subscription_topic
63
- if !result.nil?
64
- result
65
- elsif obj.is_a?(GraphQL::Schema::Object)
66
- # The root object is _already_ the subscription update:
67
- obj.object
68
- else
69
- obj
70
- end
71
- else
72
- # This is a subscription update, but this event wasn't triggered.
73
- ctx.skip
74
- end
75
- end
76
- end
77
26
  end
78
27
  end
79
28
  end
@@ -5,7 +5,6 @@ require "graphql/subscriptions/event"
5
5
  require "graphql/subscriptions/instrumentation"
6
6
  require "graphql/subscriptions/serialize"
7
7
  require "graphql/subscriptions/action_cable_subscriptions"
8
- require "graphql/subscriptions/subscription_root"
9
8
  require "graphql/subscriptions/default_subscription_resolve_extension"
10
9
 
11
10
  module GraphQL
@@ -33,9 +32,6 @@ module GraphQL
33
32
 
34
33
  instrumentation = Subscriptions::Instrumentation.new(schema: schema)
35
34
  defn.instrument(:query, instrumentation)
36
- if !schema.is_a?(Class)
37
- defn.instrument(:field, instrumentation)
38
- end
39
35
  options[:schema] = schema
40
36
  schema.subscriptions = self.new(**options)
41
37
  schema.add_subscription_extension_if_necessary
@@ -45,9 +41,6 @@ module GraphQL
45
41
  # @param schema [Class] the GraphQL schema this manager belongs to
46
42
  def initialize(schema:, broadcast: false, default_broadcastable: false, **rest)
47
43
  if broadcast
48
- if !schema.using_ast_analysis?
49
- raise ArgumentError, "`broadcast: true` requires AST analysis, add `using GraphQL::Analysis::AST` to your schema or see https://graphql-ruby.org/queries/ast_analysis.html."
50
- end
51
44
  schema.query_analyzer(Subscriptions::BroadcastAnalyzer)
52
45
  end
53
46
  @default_broadcastable = default_broadcastable
@@ -233,7 +226,7 @@ module GraphQL
233
226
  # @return [Any] normalized arguments value
234
227
  def normalize_arguments(event_name, arg_owner, args, context)
235
228
  case arg_owner
236
- when GraphQL::Field, GraphQL::InputObjectType, GraphQL::Schema::Field, Class
229
+ when GraphQL::Schema::Field, Class
237
230
  if arg_owner.is_a?(Class) && !arg_owner.kind.input_object?
238
231
  # it's a type, but not an input object
239
232
  return args
@@ -274,9 +267,7 @@ module GraphQL
274
267
  end
275
268
 
276
269
  if missing_arg_names.any?
277
- arg_owner_name = if arg_owner.is_a?(GraphQL::Field)
278
- "Subscription.#{arg_owner.name}"
279
- elsif arg_owner.is_a?(GraphQL::Schema::Field)
270
+ arg_owner_name = if arg_owner.is_a?(GraphQL::Schema::Field)
280
271
  arg_owner.path
281
272
  elsif arg_owner.is_a?(Class)
282
273
  arg_owner.graphql_name
@@ -287,9 +278,9 @@ module GraphQL
287
278
  end
288
279
 
289
280
  normalized_args
290
- when GraphQL::ListType, GraphQL::Schema::List
281
+ when GraphQL::Schema::List
291
282
  args.map { |a| normalize_arguments(event_name, arg_owner.of_type, a, context) }
292
- when GraphQL::NonNullType, GraphQL::Schema::NonNull
283
+ when GraphQL::Schema::NonNull
293
284
  normalize_arguments(event_name, arg_owner.of_type, args, context)
294
285
  else
295
286
  args
@@ -17,21 +17,15 @@ module GraphQL
17
17
  def platform_trace(platform_key, key, data)
18
18
  tracer.trace(platform_key, service: service_name) do |span|
19
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
24
20
 
25
21
  if key == 'execute_multiplex'
26
22
  operations = data[:multiplex].queries.map(&:selected_operation_name).join(', ')
27
-
28
- resource = if operations.empty?
23
+ span.resource = if operations.empty?
29
24
  first_query = data[:multiplex].queries.first
30
25
  fallback_transaction_name(first_query && first_query.context)
31
26
  else
32
27
  operations
33
28
  end
34
- span.resource = resource if resource
35
29
 
36
30
  # For top span of query, set the analytics sample rate tag, if available.
37
31
  if analytics_enabled?
@@ -45,8 +39,6 @@ module GraphQL
45
39
  span.set_tag(:query_string, data[:query].query_string)
46
40
  end
47
41
 
48
- prepare_span(key, data, span)
49
-
50
42
  yield
51
43
  end
52
44
  end
@@ -55,13 +47,6 @@ module GraphQL
55
47
  options.fetch(:service, 'ruby-graphql')
56
48
  end
57
49
 
58
- # Implement this method in a subclass to apply custom tags to datadog spans
59
- # @param key [String] The event being traced
60
- # @param data [Hash] The runtime data for this event (@see GraphQL::Tracing for keys for each event)
61
- # @param span [Datadog::Tracing::SpanOperation] The datadog span for this event
62
- def prepare_span(key, data, span)
63
- end
64
-
65
50
  def tracer
66
51
  options.fetch(:tracer, Datadog.tracer)
67
52
  end
@@ -10,10 +10,6 @@ module GraphQL
10
10
  class PlatformTracing
11
11
  class << self
12
12
  attr_accessor :platform_keys
13
-
14
- def inherited(child_class)
15
- child_class.platform_keys = self.platform_keys
16
- end
17
13
  end
18
14
 
19
15
  def initialize(options = {})
@@ -45,7 +41,7 @@ module GraphQL
45
41
 
46
42
  platform_key = if trace_field
47
43
  context = data.fetch(:query).context
48
- cached_platform_key(context, field, :field) { platform_field_key(data[:owner], field) }
44
+ cached_platform_key(context, field) { platform_field_key(data[:owner], field) }
49
45
  else
50
46
  nil
51
47
  end
@@ -61,14 +57,14 @@ module GraphQL
61
57
  when "authorized", "authorized_lazy"
62
58
  type = data.fetch(:type)
63
59
  context = data.fetch(:context)
64
- platform_key = cached_platform_key(context, type, :authorized) { platform_authorized_key(type) }
60
+ platform_key = cached_platform_key(context, type) { platform_authorized_key(type) }
65
61
  platform_trace(platform_key, key, data) do
66
62
  yield
67
63
  end
68
64
  when "resolve_type", "resolve_type_lazy"
69
65
  type = data.fetch(:type)
70
66
  context = data.fetch(:context)
71
- platform_key = cached_platform_key(context, type, :resolve_type) { platform_resolve_type_key(type) }
67
+ platform_key = cached_platform_key(context, type) { platform_resolve_type_key(type) }
72
68
  platform_trace(platform_key, key, data) do
73
69
  yield
74
70
  end
@@ -78,31 +74,8 @@ module GraphQL
78
74
  end
79
75
  end
80
76
 
81
- def instrument(type, field)
82
- return_type = field.type.unwrap
83
- case return_type
84
- when GraphQL::ScalarType, GraphQL::EnumType
85
- if field.trace || (field.trace.nil? && @trace_scalars)
86
- trace_field(type, field)
87
- else
88
- field
89
- end
90
- else
91
- trace_field(type, field)
92
- end
93
- end
94
-
95
- def trace_field(type, field)
96
- new_f = field.redefine
97
- new_f.metadata[:platform_key] = platform_field_key(type, field)
98
- new_f
99
- end
100
-
101
77
  def self.use(schema_defn, options = {})
102
78
  tracer = self.new(**options)
103
- if !schema_defn.is_a?(Class)
104
- schema_defn.instrument(:field, tracer)
105
- end
106
79
  schema_defn.tracer(tracer)
107
80
  end
108
81
 
@@ -139,7 +112,7 @@ module GraphQL
139
112
  # If the key isn't present, the given block is called and the result is cached for `key`.
140
113
  #
141
114
  # @return [String]
142
- def cached_platform_key(ctx, key, trace_phase)
115
+ def cached_platform_key(ctx, key)
143
116
  cache = ctx.namespace(self.class)[:platform_key_cache] ||= {}
144
117
  cache.fetch(key) { cache[key] = yield }
145
118
  end
@@ -6,10 +6,8 @@ require "graphql/tracing/appsignal_tracing"
6
6
  require "graphql/tracing/data_dog_tracing"
7
7
  require "graphql/tracing/new_relic_tracing"
8
8
  require "graphql/tracing/scout_tracing"
9
- require "graphql/tracing/skylight_tracing"
10
9
  require "graphql/tracing/statsd_tracing"
11
10
  require "graphql/tracing/prometheus_tracing"
12
- require "graphql/tracing/opentelemetry_tracing"
13
11
 
14
12
  if defined?(PrometheusExporter::Server)
15
13
  require "graphql/tracing/prometheus_tracing/graphql_collector"
@@ -36,7 +36,7 @@ module GraphQL
36
36
  # class name to set defaults. You can call it again in the class definition
37
37
  # to override the default (or provide a value, if the default lookup failed).
38
38
  # @param field_options [Hash] Any extra keyword arguments to pass to the `field :edges, ...` and `field :nodes, ...` configurations
39
- def edge_type(edge_type_class, edge_class: GraphQL::Relay::Edge, node_type: edge_type_class.node_type, nodes_field: self.has_nodes_field, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable, field_options: nil)
39
+ def edge_type(edge_type_class, edge_class: GraphQL::Pagination::Connection::Edge, node_type: edge_type_class.node_type, nodes_field: self.has_nodes_field, node_nullable: self.node_nullable, edges_nullable: self.edges_nullable, edge_nullable: self.edge_nullable, field_options: nil)
40
40
  # Set this connection's graphql name
41
41
  node_type_name = node_type.graphql_name
42
42
 
@@ -49,7 +49,6 @@ module GraphQL
49
49
  type: [edge_type_class, null: edge_nullable],
50
50
  null: edges_nullable,
51
51
  description: "A list of edges.",
52
- legacy_edge_class: edge_class, # This is used by the old runtime only, for EdgesInstrumentation
53
52
  connection: false,
54
53
  }
55
54
 
@@ -159,13 +158,10 @@ module GraphQL
159
158
  def edges
160
159
  if @object.is_a?(GraphQL::Pagination::Connection)
161
160
  @object.edges
162
- elsif context.interpreter?
161
+ else
163
162
  context.schema.after_lazy(object.edge_nodes) do |nodes|
164
163
  nodes.map { |n| self.class.edge_class.new(n, object) }
165
164
  end
166
- else
167
- # This is done by edges_instrumentation
168
- @object.edge_nodes
169
165
  end
170
166
  end
171
167
  end
@@ -15,16 +15,6 @@ module GraphQL
15
15
  def default_relay?
16
16
  !!@default_relay
17
17
  end
18
-
19
- def to_graphql
20
- type_defn = if method(:to_graphql).super_method.arity
21
- super(silence_deprecation_warning: true)
22
- else
23
- super
24
- end
25
- type_defn.default_relay = default_relay?
26
- type_defn
27
- end
28
18
  end
29
19
  end
30
20
  end
@@ -7,7 +7,11 @@ module GraphQL
7
7
  def self.included(child_module)
8
8
  child_module.extend(DefaultRelay)
9
9
  child_module.description("An object with an ID.")
10
- child_module.field(:id, ID, null: false, description: "ID of the object.")
10
+ child_module.field(:id, ID, null: false, description: "ID of the object.", resolver_method: :default_global_id)
11
+ end
12
+
13
+ def default_global_id
14
+ context.schema.id_from_object(object, self, context)
11
15
  end
12
16
  end
13
17
  end
@@ -14,8 +14,6 @@ require "graphql/types/relay/page_info"
14
14
  require "graphql/types/relay/base_connection"
15
15
  require "graphql/types/relay/base_edge"
16
16
  require "graphql/types/relay/node"
17
- require "graphql/types/relay/node_field"
18
- require "graphql/types/relay/nodes_field"
19
17
 
20
18
  module GraphQL
21
19
  module Types
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
- VERSION = "1.13.13"
3
+ VERSION = "2.0.0"
4
4
  end
data/lib/graphql.rb CHANGED
@@ -81,27 +81,8 @@ require "graphql/integer_decoding_error"
81
81
  require "graphql/integer_encoding_error"
82
82
  require "graphql/string_encoding_error"
83
83
  require "graphql/date_encoding_error"
84
-
85
- require "graphql/define"
86
- require "graphql/deprecation"
87
- require "graphql/base_type"
88
- require "graphql/object_type"
89
- require "graphql/enum_type"
90
- require "graphql/input_object_type"
91
- require "graphql/interface_type"
92
- require "graphql/list_type"
93
- require "graphql/non_null_type"
94
- require "graphql/union_type"
95
-
96
- require "graphql/argument"
97
- require "graphql/field"
98
84
  require "graphql/type_kinds"
99
-
100
- require "graphql/backwards_compatibility"
101
- require "graphql/scalar_type"
102
-
103
85
  require "graphql/name_validator"
104
-
105
86
  require "graphql/language"
106
87
 
107
88
  require_relative "./graphql/railtie" if defined? Rails::Railtie
@@ -116,15 +97,8 @@ require "graphql/query"
116
97
  require "graphql/types"
117
98
  require "graphql/dataloader"
118
99
  require "graphql/filter"
119
- require "graphql/internal_representation"
120
- require "graphql/directive"
121
100
  require "graphql/static_validation"
122
101
  require "graphql/execution"
123
- require "graphql/boolean_type"
124
- require "graphql/float_type"
125
- require "graphql/id_type"
126
- require "graphql/int_type"
127
- require "graphql/string_type"
128
102
  require "graphql/schema/built_in_types"
129
103
  require "graphql/schema/loader"
130
104
  require "graphql/schema/printer"
@@ -132,49 +106,11 @@ require "graphql/introspection"
132
106
  require "graphql/relay"
133
107
 
134
108
  require "graphql/version"
135
- require "graphql/compatibility"
136
- require "graphql/function"
137
109
  require "graphql/subscriptions"
138
110
  require "graphql/parse_error"
139
111
  require "graphql/backtrace"
140
112
 
141
- require "graphql/deprecated_dsl"
142
- require "graphql/authorization"
143
113
  require "graphql/unauthorized_error"
144
114
  require "graphql/unauthorized_field_error"
145
115
  require "graphql/load_application_object_failed_error"
146
- require "graphql/directive/include_directive"
147
- require "graphql/directive/skip_directive"
148
- require "graphql/directive/deprecated_directive"
149
-
150
- module GraphQL
151
- # Ruby has `deprecate_constant`,
152
- # but I don't see a way to give a nice error message in that case,
153
- # so I'm doing this instead.
154
- DEPRECATED_INT_TYPE = INT_TYPE
155
- DEPRECATED_FLOAT_TYPE = FLOAT_TYPE
156
- DEPRECATED_STRING_TYPE = STRING_TYPE
157
- DEPRECATED_BOOLEAN_TYPE = BOOLEAN_TYPE
158
- DEPRECATED_ID_TYPE = ID_TYPE
159
-
160
- remove_const :INT_TYPE
161
- remove_const :FLOAT_TYPE
162
- remove_const :STRING_TYPE
163
- remove_const :BOOLEAN_TYPE
164
- remove_const :ID_TYPE
165
-
166
- def self.const_missing(const_name)
167
- deprecated_const_name = :"DEPRECATED_#{const_name}"
168
- if const_defined?(deprecated_const_name)
169
- deprecated_type = const_get(deprecated_const_name)
170
- deprecated_caller = caller(1, 1).first
171
- # Don't warn about internal uses, like `types.Int`
172
- if !deprecated_caller.include?("lib/graphql")
173
- warn "GraphQL::#{const_name} is deprecated and will be removed in GraphQL-Ruby 2.0, use GraphQL::Types::#{deprecated_type.graphql_name} instead. (from #{deprecated_caller})"
174
- end
175
- deprecated_type
176
- else
177
- super
178
- end
179
- end
180
- end
116
+ require "graphql/deprecation"