graphql 1.13.14 → 2.0.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 (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 -185
  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 +2 -19
  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
@@ -5,49 +5,10 @@ module GraphQL
5
5
  # It delegates `[]` to the hash that's passed to `GraphQL::Query#initialize`.
6
6
  class Context
7
7
  module SharedMethods
8
- # @return [Object] The target for field resolution
9
- attr_accessor :object
10
-
11
- # @return [Hash, Array, String, Integer, Float, Boolean, nil] The resolved value for this field
12
- attr_reader :value
13
-
14
- # @return [Boolean] were any fields of this selection skipped?
15
- attr_reader :skipped
16
- alias :skipped? :skipped
17
-
18
- # @api private
19
- attr_writer :skipped
20
-
21
8
  # Return this value to tell the runtime
22
9
  # to exclude this field from the response altogether
23
10
  def skip
24
- GraphQL::Execution::Execute::SKIP
25
- end
26
-
27
- # @return [Boolean] True if this selection has been nullified by a null child
28
- def invalid_null?
29
- @invalid_null
30
- end
31
-
32
- # Remove this child from the result value
33
- # (used for null propagation and skip)
34
- # @api private
35
- def delete_child(child_ctx)
36
- @value.delete(child_ctx.key)
37
- end
38
-
39
- # Create a child context to use for `key`
40
- # @param key [String, Integer] The key in the response (name or index)
41
- # @param irep_node [InternalRepresentation::Node] The node being evaluated
42
- # @api private
43
- def spawn_child(key:, irep_node:, object:)
44
- FieldResolutionContext.new(
45
- @context,
46
- key,
47
- irep_node,
48
- self,
49
- object
50
- )
11
+ GraphQL::Execution::SKIP
51
12
  end
52
13
 
53
14
  # Add error at query-level.
@@ -72,12 +33,6 @@ module GraphQL
72
33
  def execution_errors
73
34
  @execution_errors ||= ExecutionErrors.new(self)
74
35
  end
75
-
76
- def lookahead
77
- ast_nodes = irep_node.ast_nodes
78
- field = irep_node.definition.metadata[:type_class] || raise("Lookahead is only compatible with class-based schemas")
79
- Execution::Lookahead.new(query: query, ast_nodes: ast_nodes, field: field)
80
- end
81
36
  end
82
37
 
83
38
  class ExecutionErrors
@@ -105,27 +60,6 @@ module GraphQL
105
60
  include SharedMethods
106
61
  extend Forwardable
107
62
 
108
- attr_reader :execution_strategy
109
- # `strategy` is required by GraphQL::Batch
110
- alias_method :strategy, :execution_strategy
111
-
112
- def execution_strategy=(new_strategy)
113
- # GraphQL::Batch re-assigns this value but it was previously not used
114
- # (ExecutionContext#strategy was used instead)
115
- # now it _is_ used, but it breaks GraphQL::Batch tests
116
- @execution_strategy ||= new_strategy
117
- end
118
-
119
- # @return [GraphQL::InternalRepresentation::Node] The internal representation for this query node
120
- def irep_node
121
- @irep_node ||= query.irep_selection
122
- end
123
-
124
- # @return [GraphQL::Language::Nodes::Field] The AST node for the currently-executing field
125
- def ast_node
126
- @irep_node.ast_node
127
- end
128
-
129
63
  # @return [Array<GraphQL::ExecutionError>] errors returned during execution
130
64
  attr_reader :errors
131
65
 
@@ -250,12 +184,6 @@ module GraphQL
250
184
  "#<Query::Context ...>"
251
185
  end
252
186
 
253
- # @api private
254
- def received_null_child
255
- @invalid_null = true
256
- @value = nil
257
- end
258
-
259
187
  def scoped_merge!(hash)
260
188
  @scoped_context = @scoped_context.merge(hash)
261
189
  end
@@ -264,118 +192,6 @@ module GraphQL
264
192
  scoped_merge!(key => value)
265
193
  nil
266
194
  end
267
-
268
- class FieldResolutionContext
269
- include SharedMethods
270
- include Tracing::Traceable
271
- extend Forwardable
272
-
273
- attr_reader :irep_node, :field, :parent_type, :query, :schema, :parent, :key, :type
274
- alias :selection :irep_node
275
-
276
- def initialize(context, key, irep_node, parent, object)
277
- @context = context
278
- @key = key
279
- @parent = parent
280
- @object = object
281
- @irep_node = irep_node
282
- @field = irep_node.definition
283
- @parent_type = irep_node.owner_type
284
- @type = field.type
285
- # This is needed constantly, so set it ahead of time:
286
- @query = context.query
287
- @schema = context.schema
288
- @tracers = @query.tracers
289
- # This hack flag is required by ConnectionResolve
290
- @wrapped_connection = false
291
- @wrapped_object = false
292
- end
293
-
294
- # @api private
295
- attr_accessor :wrapped_connection, :wrapped_object
296
-
297
- def path
298
- @path ||= @parent.path.dup << @key
299
- end
300
-
301
- def_delegators :@context,
302
- :[], :[]=, :key?, :fetch, :to_h, :namespace, :dig,
303
- :spawn, :warden, :errors,
304
- :execution_strategy, :strategy, :interpreter?
305
-
306
- # @return [GraphQL::Language::Nodes::Field] The AST node for the currently-executing field
307
- def ast_node
308
- @irep_node.ast_node
309
- end
310
-
311
- # Add error to current field resolution.
312
- # @param error [GraphQL::ExecutionError] an execution error
313
- # @return [void]
314
- def add_error(error)
315
- super
316
- error.ast_node ||= irep_node.ast_node
317
- error.path ||= path
318
- nil
319
- end
320
-
321
- def inspect
322
- "#<GraphQL Context @ #{irep_node.owner_type.name}.#{field.name}>"
323
- end
324
-
325
- # Set a new value for this field in the response.
326
- # It may be updated after resolving a {Lazy}.
327
- # If it is {Execute::PROPAGATE_NULL}, tell the owner to propagate null.
328
- # If it's {Execute::Execution::SKIP}, remove this field result from its parent
329
- # @param new_value [Any] The GraphQL-ready value
330
- # @api private
331
- def value=(new_value)
332
- case new_value
333
- when GraphQL::Execution::Execute::PROPAGATE_NULL, nil
334
- @invalid_null = true
335
- @value = nil
336
- if @type.kind.non_null?
337
- @parent.received_null_child
338
- end
339
- when GraphQL::Execution::Execute::SKIP
340
- @parent.skipped = true
341
- @parent.delete_child(self)
342
- else
343
- @value = new_value
344
- end
345
- end
346
-
347
- protected
348
-
349
- def received_null_child
350
- case @value
351
- when Hash
352
- self.value = GraphQL::Execution::Execute::PROPAGATE_NULL
353
- when Array
354
- if list_of_non_null_items?(@type)
355
- self.value = GraphQL::Execution::Execute::PROPAGATE_NULL
356
- end
357
- when nil
358
- # TODO This is a hack
359
- # It was already nulled out but it's getting reassigned
360
- else
361
- raise "Unexpected value for received_null_child (#{self.value.class}): #{value}"
362
- end
363
- end
364
-
365
- private
366
-
367
- def list_of_non_null_items?(type)
368
- case type
369
- when GraphQL::NonNullType
370
- # Unwrap [T]!
371
- list_of_non_null_items?(type.of_type)
372
- when GraphQL::ListType
373
- type.of_type.is_a?(GraphQL::NonNullType)
374
- else
375
- raise "Unexpected list_of_non_null_items check: #{type}"
376
- end
377
- end
378
- end
379
195
  end
380
196
  end
381
197
  end
@@ -115,20 +115,15 @@ module GraphQL
115
115
  end
116
116
  end
117
117
 
118
- if argument_owner.is_a?(Class) || argument_owner.is_a?(GraphQL::Schema::Field)
119
- # A Schema::InputObject, Schema::GraphQL::Field, Schema::Directive, logic from Query::Arguments#to_kwargs
120
- ruby_kwargs = {}
121
- values_hash.each do |key, value|
122
- ruby_kwargs[Schema::Member::BuildType.underscore(key).to_sym] = value
123
- end
124
- if argument_owner.is_a?(Class) && argument_owner < GraphQL::Schema::InputObject
125
- argument_owner.new(ruby_kwargs: ruby_kwargs, context: context, defaults_used: defaults_used)
126
- else
127
- ruby_kwargs
128
- end
118
+ # A Schema::InputObject, Schema::GraphQL::Field, Schema::Directive, logic from Interpreter::Arguments
119
+ ruby_kwargs = {}
120
+ values_hash.each do |key, value|
121
+ ruby_kwargs[Schema::Member::BuildType.underscore(key).to_sym] = value
122
+ end
123
+ if argument_owner.is_a?(Class) && argument_owner < GraphQL::Schema::InputObject
124
+ argument_owner.new(ruby_kwargs: ruby_kwargs, context: context, defaults_used: defaults_used)
129
125
  else
130
- result = argument_owner.arguments_class.new(values_hash, context: context, defaults_used: defaults_used)
131
- result.prepare
126
+ ruby_kwargs
132
127
  end
133
128
  end
134
129
  end
@@ -16,10 +16,8 @@ module GraphQL
16
16
  class ValidationPipeline
17
17
  attr_reader :max_depth, :max_complexity
18
18
 
19
- def initialize(query:, validate:, parse_error:, operation_name_error:, max_depth:, max_complexity:)
19
+ def initialize(query:, parse_error:, operation_name_error:, max_depth:, max_complexity:)
20
20
  @validation_errors = []
21
- @internal_representation = nil
22
- @validate = validate
23
21
  @parse_error = parse_error
24
22
  @operation_name_error = operation_name_error
25
23
  @query = query
@@ -42,12 +40,6 @@ module GraphQL
42
40
  @validation_errors
43
41
  end
44
42
 
45
- # @return [Hash<String, nil => GraphQL::InternalRepresentation::Node] Operation name -> Irep node pairs
46
- def internal_representation
47
- ensure_has_validated
48
- @internal_representation
49
- end
50
-
51
43
  def analyzers
52
44
  ensure_has_validated
53
45
  @query_analyzers
@@ -63,7 +55,7 @@ module GraphQL
63
55
 
64
56
  if @parse_error
65
57
  # This is kind of crazy: we push the parse error into `ctx`
66
- # in {DefaultParseError} so that users can _opt out_ by redefining that hook.
58
+ # in `def self.parse_error` by default so that users can _opt out_ by redefining that hook.
67
59
  # That means we can't _re-add_ the error here (otherwise we'd either
68
60
  # add it twice _or_ override the user's choice to not add it).
69
61
  # So we just have to know that it was invalid and go from there.
@@ -72,9 +64,8 @@ module GraphQL
72
64
  elsif @operation_name_error
73
65
  @validation_errors << @operation_name_error
74
66
  else
75
- validation_result = @schema.static_validator.validate(@query, validate: @validate, timeout: @schema.validate_timeout, max_errors: @schema.validate_max_errors)
67
+ validation_result = @schema.static_validator.validate(@query, validate: @query.validate, timeout: @schema.validate_timeout, max_errors: @schema.validate_max_errors)
76
68
  @validation_errors.concat(validation_result[:errors])
77
- @internal_representation = validation_result[:irep]
78
69
 
79
70
  if @validation_errors.empty?
80
71
  @validation_errors.concat(@query.variables.errors)
@@ -100,35 +91,15 @@ module GraphQL
100
91
  def build_analyzers(schema, max_depth, max_complexity)
101
92
  qa = schema.query_analyzers.dup
102
93
 
103
- # Filter out the built in authorization analyzer.
104
- # It is deprecated and does not have an AST analyzer alternative.
105
- qa = qa.select do |analyzer|
106
- if analyzer == GraphQL::Authorization::Analyzer && schema.using_ast_analysis?
107
- raise "The Authorization analyzer is not supported with AST Analyzers"
108
- else
109
- true
110
- end
111
- end
112
-
113
94
  if max_depth || max_complexity
114
95
  # Depending on the analysis engine, we must use different analyzers
115
96
  # remove this once everything has switched over to AST analyzers
116
- if schema.using_ast_analysis?
117
- if max_depth
118
- qa << GraphQL::Analysis::AST::MaxQueryDepth
119
- end
120
- if max_complexity
121
- qa << GraphQL::Analysis::AST::MaxQueryComplexity
122
- end
123
- else
124
- if max_depth
125
- qa << GraphQL::Analysis::MaxQueryDepth.new(max_depth)
126
- end
127
- if max_complexity
128
- qa << GraphQL::Analysis::MaxQueryComplexity.new(max_complexity)
129
- end
97
+ if max_depth
98
+ qa << GraphQL::Analysis::AST::MaxQueryDepth
99
+ end
100
+ if max_complexity
101
+ qa << GraphQL::Analysis::AST::MaxQueryComplexity
130
102
  end
131
-
132
103
  qa
133
104
  else
134
105
  qa
@@ -14,7 +14,7 @@ module GraphQL
14
14
  schema = ctx.schema
15
15
  @context = ctx
16
16
 
17
- @provided_variables = GraphQL::Argument.deep_stringify(provided_variables)
17
+ @provided_variables = deep_stringify(provided_variables)
18
18
  @errors = []
19
19
  @storage = ast_variables.each_with_object({}) do |ast_variable, memo|
20
20
  # Find the right value for this variable:
@@ -34,25 +34,12 @@ module GraphQL
34
34
  if validation_result.valid?
35
35
  if value_was_provided
36
36
  # Add the variable if a value was provided
37
- memo[variable_name] = if ctx.interpreter?
38
- provided_value
39
- elsif provided_value.nil?
40
- nil
41
- else
42
- schema.error_handler.with_error_handling(context) do
43
- variable_type.coerce_input(provided_value, ctx)
44
- end
45
- end
37
+ memo[variable_name] = provided_value
46
38
  elsif default_value != nil
47
- memo[variable_name] = if ctx.interpreter?
48
- if default_value.is_a?(Language::Nodes::NullValue)
49
- nil
50
- else
51
- default_value
52
- end
39
+ memo[variable_name] = if default_value.is_a?(Language::Nodes::NullValue)
40
+ nil
53
41
  else
54
- # Add the variable if it wasn't provided but it has a default value (including `null`)
55
- GraphQL::Query::LiteralInput.coerce(variable_type, default_value, self)
42
+ default_value
56
43
  end
57
44
  end
58
45
  end
@@ -73,6 +60,23 @@ module GraphQL
73
60
  end
74
61
 
75
62
  def_delegators :@storage, :length, :key?, :[], :fetch, :to_h
63
+
64
+ private
65
+
66
+ def deep_stringify(val)
67
+ case val
68
+ when Array
69
+ val.map { |v| deep_stringify(v) }
70
+ when Hash
71
+ new_val = {}
72
+ val.each do |k, v|
73
+ new_val[k.to_s] = deep_stringify(v)
74
+ end
75
+ new_val
76
+ else
77
+ val
78
+ end
79
+ end
76
80
  end
77
81
  end
78
82
  end
data/lib/graphql/query.rb CHANGED
@@ -1,13 +1,9 @@
1
1
  # frozen_string_literal: true
2
- require "graphql/query/arguments"
3
- require "graphql/query/arguments_cache"
4
2
  require "graphql/query/context"
5
- require "graphql/query/executor"
6
3
  require "graphql/query/fingerprint"
7
4
  require "graphql/query/literal_input"
8
5
  require "graphql/query/null_context"
9
6
  require "graphql/query/result"
10
- require "graphql/query/serial_execution"
11
7
  require "graphql/query/variables"
12
8
  require "graphql/query/input_validation_result"
13
9
  require "graphql/query/variable_validation_error"
@@ -82,13 +78,7 @@ module GraphQL
82
78
  def initialize(schema, query_string = nil, query: nil, document: nil, context: nil, variables: nil, validate: true, subscription_topic: nil, operation_name: nil, root_value: nil, max_depth: schema.max_depth, max_complexity: schema.max_complexity, except: nil, only: nil, warden: nil)
83
79
  # Even if `variables: nil` is passed, use an empty hash for simpler logic
84
80
  variables ||= {}
85
-
86
- # Use the `.graphql_definition` here which will return legacy types instead of classes
87
- if schema.is_a?(Class) && !schema.interpreter?
88
- schema = schema.graphql_definition
89
- end
90
81
  @schema = schema
91
- @interpreter = @schema.interpreter?
92
82
  @filter = schema.default_filter.merge(except: except, only: only)
93
83
  @context = schema.context_class.new(query: self, object: root_value, values: context)
94
84
  @warden = warden
@@ -154,7 +144,7 @@ module GraphQL
154
144
  end
155
145
 
156
146
  def interpreter?
157
- @interpreter
147
+ true
158
148
  end
159
149
 
160
150
  attr_accessor :multiplex
@@ -169,7 +159,6 @@ module GraphQL
169
159
  @lookahead ||= begin
170
160
  ast_node = selected_operation
171
161
  root_type = warden.root_type_for_operation(ast_node.operation_type || "query")
172
- root_type = root_type.type_class || raise("Invariant: `lookahead` only works with class-based types")
173
162
  GraphQL::Execution::Lookahead.new(query: self, root_type: root_type, ast_nodes: [ast_node])
174
163
  end
175
164
  end
@@ -199,7 +188,7 @@ module GraphQL
199
188
  # @return [Hash] A GraphQL response, with `"data"` and/or `"errors"` keys
200
189
  def result
201
190
  if !@executed
202
- Execution::Multiplex.run_queries(@schema, [self], context: @context)
191
+ Execution::Multiplex.run_all(@schema, [self], context: @context)
203
192
  end
204
193
  @result ||= Query::Result.new(query: self, values: @result_values)
205
194
  end
@@ -237,35 +226,17 @@ module GraphQL
237
226
  end
238
227
  end
239
228
 
240
- def irep_selection
241
- @selection ||= begin
242
- if selected_operation && internal_representation
243
- internal_representation.operation_definitions[selected_operation.name]
244
- else
245
- nil
246
- end
247
- end
248
- end
249
-
250
229
  # Node-level cache for calculating arguments. Used during execution and query analysis.
251
230
  # @param ast_node [GraphQL::Language::Nodes::AbstractNode]
252
231
  # @param definition [GraphQL::Schema::Field]
253
232
  # @param parent_object [GraphQL::Schema::Object]
254
233
  # @return Hash{Symbol => Object}
255
234
  def arguments_for(ast_node, definition, parent_object: nil)
256
- if interpreter?
257
- arguments_cache.fetch(ast_node, definition, parent_object)
258
- else
259
- arguments_cache[ast_node][definition]
260
- end
235
+ arguments_cache.fetch(ast_node, definition, parent_object)
261
236
  end
262
237
 
263
238
  def arguments_cache
264
- if interpreter?
265
- @arguments_cache ||= Execution::Interpreter::ArgumentsCache.new(self)
266
- else
267
- @arguments_cache ||= ArgumentsCache.build(self)
268
- end
239
+ @arguments_cache ||= Execution::Interpreter::ArgumentsCache.new(self)
269
240
  end
270
241
 
271
242
  # A version of the given query string, with:
@@ -308,7 +279,7 @@ module GraphQL
308
279
  with_prepared_ast { @validation_pipeline }
309
280
  end
310
281
 
311
- def_delegators :validation_pipeline, :validation_errors, :internal_representation,
282
+ def_delegators :validation_pipeline, :validation_errors,
312
283
  :analyzers, :ast_analyzers, :max_depth, :max_complexity
313
284
 
314
285
  attr_accessor :analysis_errors
@@ -434,7 +405,6 @@ module GraphQL
434
405
 
435
406
  @validation_pipeline = GraphQL::Query::ValidationPipeline.new(
436
407
  query: self,
437
- validate: @validate,
438
408
  parse_error: parse_error,
439
409
  operation_name_error: operation_name_error,
440
410
  max_depth: @max_depth,
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  module GraphQL
4
3
  class Railtie < Rails::Railtie
5
4
  config.before_configuration do
@@ -10,108 +9,5 @@ module GraphQL
10
9
  Language::Parser.cache ||= Language::Cache.new(Pathname.new(Bootsnap::CompileCache::ISeq.cache_dir).join('graphql'))
11
10
  end
12
11
  end
13
-
14
- rake_tasks do
15
- # Defer this so that you only need the `parser` gem when you _run_ the upgrader
16
- def load_upgraders
17
- require_relative './upgrader/member'
18
- require_relative './upgrader/schema'
19
- end
20
-
21
- namespace :graphql do
22
- task :upgrade, [:dir] do |t, args|
23
- unless (dir = args[:dir])
24
- fail 'You have to give me a directory where your GraphQL schema and types live. ' \
25
- 'For example: `bin/rake graphql:upgrade[app/graphql/**/*]`'
26
- end
27
-
28
- Dir[dir].each do |file|
29
- # Members (types, interfaces, etc.)
30
- if file =~ /.*_(type|interface|enum|union|)\.rb$/
31
- Rake::Task["graphql:upgrade:member"].execute(Struct.new(:member_file).new(file))
32
- end
33
- end
34
-
35
- puts "Upgrade complete! Note that this is a best-effort approach, and may very well contain some bugs."
36
- puts "Don't forget to create the base objects. For example, you could run:"
37
- puts "\tbin/rake graphql:upgrade:create_base_objects[app/graphql]"
38
- end
39
-
40
- namespace :upgrade do
41
- task :create_base_objects, [:base_dir] do |t, args|
42
- unless (base_dir = args[:base_dir])
43
- fail 'You have to give me a directory where your GraphQL types live. ' \
44
- 'For example: `bin/rake graphql:upgrade:create_base_objects[app/graphql]`'
45
- end
46
-
47
- destination_file = File.join(base_dir, "types", "base_scalar.rb")
48
- unless File.exists?(destination_file)
49
- FileUtils.mkdir_p(File.dirname(destination_file))
50
- File.open(destination_file, 'w') do |f|
51
- f.puts "class Types::BaseScalar < GraphQL::Schema::Scalar\nend"
52
- end
53
- end
54
-
55
- destination_file = File.join(base_dir, "types", "base_input_object.rb")
56
- unless File.exists?(destination_file)
57
- FileUtils.mkdir_p(File.dirname(destination_file))
58
- File.open(destination_file, 'w') do |f|
59
- f.puts "class Types::BaseInputObject < GraphQL::Schema::InputObject\nend"
60
- end
61
- end
62
-
63
- destination_file = File.join(base_dir, "types", "base_enum.rb")
64
- unless File.exists?(destination_file)
65
- FileUtils.mkdir_p(File.dirname(destination_file))
66
- File.open(destination_file, 'w') do |f|
67
- f.puts "class Types::BaseEnum < GraphQL::Schema::Enum\nend"
68
- end
69
- end
70
-
71
- destination_file = File.join(base_dir, "types", "base_union.rb")
72
- unless File.exists?(destination_file)
73
- FileUtils.mkdir_p(File.dirname(destination_file))
74
- File.open(destination_file, 'w') do |f|
75
- f.puts "class Types::BaseUnion < GraphQL::Schema::Union\nend"
76
- end
77
- end
78
-
79
- destination_file = File.join(base_dir, "types", "base_interface.rb")
80
- unless File.exists?(destination_file)
81
- FileUtils.mkdir_p(File.dirname(destination_file))
82
- File.open(destination_file, 'w') do |f|
83
- f.puts "module Types::BaseInterface\n include GraphQL::Schema::Interface\nend"
84
- end
85
- end
86
-
87
- destination_file = File.join(base_dir, "types", "base_object.rb")
88
- unless File.exists?(destination_file)
89
- File.open(destination_file, 'w') do |f|
90
- f.puts "class Types::BaseObject < GraphQL::Schema::Object\nend"
91
- end
92
- end
93
- end
94
-
95
- task :schema, [:schema_file] do |t, args|
96
- schema_file = args.schema_file
97
- load_upgraders
98
- upgrader = GraphQL::Upgrader::Schema.new File.read(schema_file)
99
-
100
- puts "- Transforming schema #{schema_file}"
101
- File.open(schema_file, 'w') { |f| f.write upgrader.upgrade }
102
- end
103
-
104
- task :member, [:member_file] do |t, args|
105
- member_file = args.member_file
106
- load_upgraders
107
- upgrader = GraphQL::Upgrader::Member.new File.read(member_file)
108
- next unless upgrader.upgradeable?
109
-
110
- puts "- Transforming member #{member_file}"
111
- File.open(member_file, 'w') { |f| f.write upgrader.upgrade }
112
- end
113
- end
114
- end
115
- end
116
12
  end
117
13
  end
@@ -35,10 +35,6 @@ module GraphQL
35
35
  # @param context [GraphQL::Query::Context] The surrounding `ctx`, will be passed to the connection if provided (this is required for cursor encoders)
36
36
  # @param edge_class [Class] The class to wrap `item` with (defaults to the connection's edge class)
37
37
  def initialize(collection:, item:, parent: nil, context: nil, edge_class: nil)
38
- if context.nil?
39
- caller_loc = caller(2, 1).first
40
- GraphQL::Deprecation.warn("`context: ...` will be required by `RangeAdd.new` in GraphQL-Ruby 2.0. Add `context: context` to the call at #{caller_loc}.")
41
- end
42
38
  if context && context.schema.new_connections?
43
39
  conn_class = context.schema.connections.wrapper_for(collection)
44
40
  # The rest will be added by ConnectionExtension
data/lib/graphql/relay.rb CHANGED
@@ -1,18 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'graphql/relay/page_info'
4
- require 'graphql/relay/edge'
5
- require 'graphql/relay/edge_type'
6
- require 'graphql/relay/edges_instrumentation'
7
- require 'graphql/relay/base_connection'
8
- require 'graphql/relay/array_connection'
9
3
  require 'graphql/relay/range_add'
10
- require 'graphql/relay/relation_connection'
11
- require 'graphql/relay/mongo_relation_connection'
12
- require 'graphql/relay/global_id_resolve'
13
- require 'graphql/relay/mutation'
14
- require 'graphql/relay/node'
15
- require 'graphql/relay/connection_instrumentation'
16
- require 'graphql/relay/connection_resolve'
17
- require 'graphql/relay/connection_type'
18
- require 'graphql/relay/type_extensions'
@@ -136,14 +136,7 @@ module GraphQL
136
136
  end
137
137
 
138
138
  def add_type(type, owner:, late_types:, path:)
139
- if type.respond_to?(:metadata) && type.metadata.is_a?(Hash)
140
- type_class = type.metadata[:type_class]
141
- if type_class.nil?
142
- raise ArgumentError, "Can't add legacy type: #{type} (#{type.class})"
143
- else
144
- type = type_class
145
- end
146
- elsif type.is_a?(String) || type.is_a?(GraphQL::Schema::LateBoundType)
139
+ if type.is_a?(String) || type.is_a?(GraphQL::Schema::LateBoundType)
147
140
  late_types << [owner, type]
148
141
  return
149
142
  end