graphql 1.13.10 → 2.0.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.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
  3. data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
  4. data/lib/graphql/analysis/ast/query_depth.rb +0 -1
  5. data/lib/graphql/analysis/ast/visitor.rb +1 -1
  6. data/lib/graphql/analysis/ast.rb +0 -10
  7. data/lib/graphql/analysis.rb +0 -7
  8. data/lib/graphql/backtrace/table.rb +0 -18
  9. data/lib/graphql/backtrace/tracer.rb +1 -2
  10. data/lib/graphql/backtrace.rb +2 -8
  11. data/lib/graphql/dataloader/null_dataloader.rb +3 -1
  12. data/lib/graphql/dig.rb +1 -1
  13. data/lib/graphql/execution/errors.rb +1 -9
  14. data/lib/graphql/execution/interpreter/runtime.rb +17 -31
  15. data/lib/graphql/execution/interpreter.rb +0 -22
  16. data/lib/graphql/execution/lazy.rb +1 -1
  17. data/lib/graphql/execution/lookahead.rb +6 -13
  18. data/lib/graphql/execution/multiplex.rb +50 -107
  19. data/lib/graphql/execution.rb +11 -3
  20. data/lib/graphql/introspection/dynamic_fields.rb +3 -8
  21. data/lib/graphql/introspection/entry_points.rb +2 -15
  22. data/lib/graphql/language/document_from_schema_definition.rb +0 -17
  23. data/lib/graphql/pagination/connections.rb +2 -28
  24. data/lib/graphql/query/context.rb +97 -194
  25. data/lib/graphql/query/input_validation_result.rb +10 -1
  26. data/lib/graphql/query/validation_pipeline.rb +8 -37
  27. data/lib/graphql/query/variables.rb +22 -18
  28. data/lib/graphql/query.rb +5 -36
  29. data/lib/graphql/railtie.rb +0 -104
  30. data/lib/graphql/relay.rb +0 -15
  31. data/lib/graphql/schema/addition.rb +1 -8
  32. data/lib/graphql/schema/argument.rb +5 -26
  33. data/lib/graphql/schema/build_from_definition.rb +0 -1
  34. data/lib/graphql/schema/directive.rb +0 -21
  35. data/lib/graphql/schema/enum.rb +4 -23
  36. data/lib/graphql/schema/enum_value.rb +0 -22
  37. data/lib/graphql/schema/field.rb +70 -230
  38. data/lib/graphql/schema/input_object.rb +21 -68
  39. data/lib/graphql/schema/interface.rb +0 -25
  40. data/lib/graphql/schema/introspection_system.rb +3 -8
  41. data/lib/graphql/schema/late_bound_type.rb +2 -2
  42. data/lib/graphql/schema/list.rb +2 -7
  43. data/lib/graphql/schema/loader.rb +0 -1
  44. data/lib/graphql/schema/member/base_dsl_methods.rb +0 -5
  45. data/lib/graphql/schema/member/build_type.rb +4 -6
  46. data/lib/graphql/schema/member/has_arguments.rb +50 -24
  47. data/lib/graphql/schema/member/has_fields.rb +2 -2
  48. data/lib/graphql/schema/member/has_interfaces.rb +1 -3
  49. data/lib/graphql/schema/member/validates_input.rb +2 -2
  50. data/lib/graphql/schema/member.rb +0 -6
  51. data/lib/graphql/schema/mutation.rb +0 -9
  52. data/lib/graphql/schema/non_null.rb +1 -7
  53. data/lib/graphql/schema/object.rb +7 -42
  54. data/lib/graphql/schema/relay_classic_mutation.rb +49 -42
  55. data/lib/graphql/schema/resolver/has_payload_type.rb +11 -1
  56. data/lib/graphql/schema/resolver.rb +23 -45
  57. data/lib/graphql/schema/scalar.rb +4 -19
  58. data/lib/graphql/schema/subscription.rb +0 -7
  59. data/lib/graphql/schema/union.rb +0 -16
  60. data/lib/graphql/schema/warden.rb +2 -2
  61. data/lib/graphql/schema/wrapper.rb +0 -5
  62. data/lib/graphql/schema.rb +106 -944
  63. data/lib/graphql/static_validation/base_visitor.rb +4 -21
  64. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
  65. data/lib/graphql/static_validation/validator.rb +2 -24
  66. data/lib/graphql/static_validation.rb +0 -2
  67. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
  68. data/lib/graphql/subscriptions/event.rb +1 -1
  69. data/lib/graphql/subscriptions/instrumentation.rb +0 -51
  70. data/lib/graphql/subscriptions.rb +14 -16
  71. data/lib/graphql/tracing/platform_tracing.rb +0 -23
  72. data/lib/graphql/tracing.rb +0 -1
  73. data/lib/graphql/types/relay/connection_behaviors.rb +2 -6
  74. data/lib/graphql/types/relay/default_relay.rb +0 -10
  75. data/lib/graphql/types/relay/node_behaviors.rb +5 -1
  76. data/lib/graphql/types/relay.rb +0 -2
  77. data/lib/graphql/version.rb +1 -1
  78. data/lib/graphql.rb +1 -65
  79. metadata +2 -128
  80. data/lib/graphql/analysis/analyze_query.rb +0 -98
  81. data/lib/graphql/analysis/field_usage.rb +0 -45
  82. data/lib/graphql/analysis/max_query_complexity.rb +0 -26
  83. data/lib/graphql/analysis/max_query_depth.rb +0 -26
  84. data/lib/graphql/analysis/query_complexity.rb +0 -88
  85. data/lib/graphql/analysis/query_depth.rb +0 -43
  86. data/lib/graphql/analysis/reducer_state.rb +0 -48
  87. data/lib/graphql/argument.rb +0 -131
  88. data/lib/graphql/authorization.rb +0 -82
  89. data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
  90. data/lib/graphql/backwards_compatibility.rb +0 -61
  91. data/lib/graphql/base_type.rb +0 -232
  92. data/lib/graphql/boolean_type.rb +0 -2
  93. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
  94. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
  95. data/lib/graphql/compatibility/execution_specification.rb +0 -436
  96. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
  97. data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
  98. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
  99. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
  100. data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
  101. data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
  102. data/lib/graphql/compatibility.rb +0 -5
  103. data/lib/graphql/define/assign_argument.rb +0 -12
  104. data/lib/graphql/define/assign_connection.rb +0 -13
  105. data/lib/graphql/define/assign_enum_value.rb +0 -18
  106. data/lib/graphql/define/assign_global_id_field.rb +0 -11
  107. data/lib/graphql/define/assign_mutation_function.rb +0 -34
  108. data/lib/graphql/define/assign_object_field.rb +0 -42
  109. data/lib/graphql/define/defined_object_proxy.rb +0 -53
  110. data/lib/graphql/define/instance_definable.rb +0 -240
  111. data/lib/graphql/define/no_definition_error.rb +0 -7
  112. data/lib/graphql/define/non_null_with_bang.rb +0 -16
  113. data/lib/graphql/define/type_definer.rb +0 -31
  114. data/lib/graphql/define.rb +0 -31
  115. data/lib/graphql/deprecated_dsl.rb +0 -55
  116. data/lib/graphql/directive/deprecated_directive.rb +0 -2
  117. data/lib/graphql/directive/include_directive.rb +0 -2
  118. data/lib/graphql/directive/skip_directive.rb +0 -2
  119. data/lib/graphql/directive.rb +0 -107
  120. data/lib/graphql/enum_type.rb +0 -133
  121. data/lib/graphql/execution/execute.rb +0 -333
  122. data/lib/graphql/execution/flatten.rb +0 -40
  123. data/lib/graphql/execution/typecast.rb +0 -50
  124. data/lib/graphql/field/resolve.rb +0 -59
  125. data/lib/graphql/field.rb +0 -226
  126. data/lib/graphql/float_type.rb +0 -2
  127. data/lib/graphql/function.rb +0 -128
  128. data/lib/graphql/id_type.rb +0 -2
  129. data/lib/graphql/input_object_type.rb +0 -138
  130. data/lib/graphql/int_type.rb +0 -2
  131. data/lib/graphql/interface_type.rb +0 -72
  132. data/lib/graphql/internal_representation/document.rb +0 -27
  133. data/lib/graphql/internal_representation/node.rb +0 -206
  134. data/lib/graphql/internal_representation/print.rb +0 -51
  135. data/lib/graphql/internal_representation/rewrite.rb +0 -184
  136. data/lib/graphql/internal_representation/scope.rb +0 -88
  137. data/lib/graphql/internal_representation/visit.rb +0 -36
  138. data/lib/graphql/internal_representation.rb +0 -7
  139. data/lib/graphql/list_type.rb +0 -80
  140. data/lib/graphql/non_null_type.rb +0 -71
  141. data/lib/graphql/object_type.rb +0 -130
  142. data/lib/graphql/query/arguments.rb +0 -189
  143. data/lib/graphql/query/arguments_cache.rb +0 -24
  144. data/lib/graphql/query/executor.rb +0 -52
  145. data/lib/graphql/query/literal_input.rb +0 -136
  146. data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
  147. data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
  148. data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
  149. data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
  150. data/lib/graphql/query/serial_execution.rb +0 -40
  151. data/lib/graphql/relay/array_connection.rb +0 -83
  152. data/lib/graphql/relay/base_connection.rb +0 -189
  153. data/lib/graphql/relay/connection_instrumentation.rb +0 -54
  154. data/lib/graphql/relay/connection_resolve.rb +0 -43
  155. data/lib/graphql/relay/connection_type.rb +0 -54
  156. data/lib/graphql/relay/edge.rb +0 -27
  157. data/lib/graphql/relay/edge_type.rb +0 -19
  158. data/lib/graphql/relay/edges_instrumentation.rb +0 -39
  159. data/lib/graphql/relay/global_id_resolve.rb +0 -17
  160. data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
  161. data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
  162. data/lib/graphql/relay/mutation/resolve.rb +0 -56
  163. data/lib/graphql/relay/mutation/result.rb +0 -38
  164. data/lib/graphql/relay/mutation.rb +0 -106
  165. data/lib/graphql/relay/node.rb +0 -39
  166. data/lib/graphql/relay/page_info.rb +0 -7
  167. data/lib/graphql/relay/relation_connection.rb +0 -188
  168. data/lib/graphql/relay/type_extensions.rb +0 -32
  169. data/lib/graphql/scalar_type.rb +0 -91
  170. data/lib/graphql/schema/catchall_middleware.rb +0 -35
  171. data/lib/graphql/schema/default_parse_error.rb +0 -10
  172. data/lib/graphql/schema/default_type_error.rb +0 -17
  173. data/lib/graphql/schema/member/accepts_definition.rb +0 -164
  174. data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
  175. data/lib/graphql/schema/member/instrumentation.rb +0 -131
  176. data/lib/graphql/schema/middleware_chain.rb +0 -82
  177. data/lib/graphql/schema/possible_types.rb +0 -44
  178. data/lib/graphql/schema/rescue_middleware.rb +0 -60
  179. data/lib/graphql/schema/timeout_middleware.rb +0 -88
  180. data/lib/graphql/schema/traversal.rb +0 -228
  181. data/lib/graphql/schema/validation.rb +0 -313
  182. data/lib/graphql/static_validation/default_visitor.rb +0 -15
  183. data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
  184. data/lib/graphql/string_type.rb +0 -2
  185. data/lib/graphql/subscriptions/subscription_root.rb +0 -76
  186. data/lib/graphql/tracing/skylight_tracing.rb +0 -70
  187. data/lib/graphql/types/relay/node_field.rb +0 -24
  188. data/lib/graphql/types/relay/nodes_field.rb +0 -43
  189. data/lib/graphql/union_type.rb +0 -115
  190. data/lib/graphql/upgrader/member.rb +0 -937
  191. 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
@@ -63,17 +56,24 @@ module GraphQL
63
56
  # @param args [Hash<String, Symbol => Object]
64
57
  # @param object [Object]
65
58
  # @param scope [Symbol, String]
59
+ # @param context [Hash]
66
60
  # @return [void]
67
- def trigger(event_name, args, object, scope: nil)
61
+ def trigger(event_name, args, object, scope: nil, context: {})
62
+ # Make something as context-like as possible, even though there isn't a current query:
63
+ context = @schema.context_class.new(
64
+ query: GraphQL::Query.new(@schema, "", validate: false),
65
+ object: nil,
66
+ values: context
67
+ )
68
68
  event_name = event_name.to_s
69
69
 
70
70
  # Try with the verbatim input first:
71
- field = @schema.get_field(@schema.subscription, event_name)
71
+ field = @schema.get_field(@schema.subscription, event_name, context)
72
72
 
73
73
  if field.nil?
74
74
  # And if it wasn't found, normalize it:
75
75
  normalized_event_name = normalize_name(event_name)
76
- field = @schema.get_field(@schema.subscription, normalized_event_name)
76
+ field = @schema.get_field(@schema.subscription, normalized_event_name, context)
77
77
  if field.nil?
78
78
  raise InvalidTriggerError, "No subscription matching trigger: #{event_name} (looked for #{@schema.subscription.graphql_name}.#{normalized_event_name})"
79
79
  end
@@ -233,7 +233,7 @@ module GraphQL
233
233
  # @return [Any] normalized arguments value
234
234
  def normalize_arguments(event_name, arg_owner, args, context)
235
235
  case arg_owner
236
- when GraphQL::Field, GraphQL::InputObjectType, GraphQL::Schema::Field, Class
236
+ when GraphQL::Schema::Field, Class
237
237
  if arg_owner.is_a?(Class) && !arg_owner.kind.input_object?
238
238
  # it's a type, but not an input object
239
239
  return args
@@ -274,9 +274,7 @@ module GraphQL
274
274
  end
275
275
 
276
276
  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)
277
+ arg_owner_name = if arg_owner.is_a?(GraphQL::Schema::Field)
280
278
  arg_owner.path
281
279
  elsif arg_owner.is_a?(Class)
282
280
  arg_owner.graphql_name
@@ -287,9 +285,9 @@ module GraphQL
287
285
  end
288
286
 
289
287
  normalized_args
290
- when GraphQL::ListType, GraphQL::Schema::List
288
+ when GraphQL::Schema::List
291
289
  args.map { |a| normalize_arguments(event_name, arg_owner.of_type, a, context) }
292
- when GraphQL::NonNullType, GraphQL::Schema::NonNull
290
+ when GraphQL::Schema::NonNull
293
291
  normalize_arguments(event_name, arg_owner.of_type, args, context)
294
292
  else
295
293
  args
@@ -74,31 +74,8 @@ module GraphQL
74
74
  end
75
75
  end
76
76
 
77
- def instrument(type, field)
78
- return_type = field.type.unwrap
79
- case return_type
80
- when GraphQL::ScalarType, GraphQL::EnumType
81
- if field.trace || (field.trace.nil? && @trace_scalars)
82
- trace_field(type, field)
83
- else
84
- field
85
- end
86
- else
87
- trace_field(type, field)
88
- end
89
- end
90
-
91
- def trace_field(type, field)
92
- new_f = field.redefine
93
- new_f.metadata[:platform_key] = platform_field_key(type, field)
94
- new_f
95
- end
96
-
97
77
  def self.use(schema_defn, options = {})
98
78
  tracer = self.new(**options)
99
- if !schema_defn.is_a?(Class)
100
- schema_defn.instrument(:field, tracer)
101
- end
102
79
  schema_defn.tracer(tracer)
103
80
  end
104
81
 
@@ -6,7 +6,6 @@ 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
11
 
@@ -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.10"
3
+ VERSION = "2.0.2"
4
4
  end
data/lib/graphql.rb CHANGED
@@ -81,26 +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/base_type"
87
- require "graphql/object_type"
88
- require "graphql/enum_type"
89
- require "graphql/input_object_type"
90
- require "graphql/interface_type"
91
- require "graphql/list_type"
92
- require "graphql/non_null_type"
93
- require "graphql/union_type"
94
-
95
- require "graphql/argument"
96
- require "graphql/field"
97
84
  require "graphql/type_kinds"
98
-
99
- require "graphql/backwards_compatibility"
100
- require "graphql/scalar_type"
101
-
102
85
  require "graphql/name_validator"
103
-
104
86
  require "graphql/language"
105
87
 
106
88
  require_relative "./graphql/railtie" if defined? Rails::Railtie
@@ -115,16 +97,8 @@ require "graphql/query"
115
97
  require "graphql/types"
116
98
  require "graphql/dataloader"
117
99
  require "graphql/filter"
118
- require "graphql/internal_representation"
119
- require "graphql/directive"
120
100
  require "graphql/static_validation"
121
101
  require "graphql/execution"
122
- require "graphql/deprecation"
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"