graphql 1.13.10 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) 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.rb +0 -15
  29. data/lib/graphql/schema/addition.rb +1 -8
  30. data/lib/graphql/schema/argument.rb +1 -25
  31. data/lib/graphql/schema/build_from_definition.rb +0 -1
  32. data/lib/graphql/schema/directive.rb +0 -21
  33. data/lib/graphql/schema/enum.rb +1 -18
  34. data/lib/graphql/schema/enum_value.rb +0 -22
  35. data/lib/graphql/schema/field.rb +2 -183
  36. data/lib/graphql/schema/input_object.rb +9 -56
  37. data/lib/graphql/schema/interface.rb +0 -25
  38. data/lib/graphql/schema/introspection_system.rb +3 -8
  39. data/lib/graphql/schema/late_bound_type.rb +2 -2
  40. data/lib/graphql/schema/list.rb +0 -6
  41. data/lib/graphql/schema/loader.rb +0 -1
  42. data/lib/graphql/schema/member/base_dsl_methods.rb +0 -5
  43. data/lib/graphql/schema/member/build_type.rb +4 -6
  44. data/lib/graphql/schema/member/has_arguments.rb +14 -18
  45. data/lib/graphql/schema/member/has_fields.rb +2 -2
  46. data/lib/graphql/schema/member/has_interfaces.rb +0 -2
  47. data/lib/graphql/schema/member.rb +0 -6
  48. data/lib/graphql/schema/mutation.rb +0 -9
  49. data/lib/graphql/schema/non_null.rb +1 -7
  50. data/lib/graphql/schema/object.rb +0 -40
  51. data/lib/graphql/schema/relay_classic_mutation.rb +17 -28
  52. data/lib/graphql/schema/scalar.rb +0 -15
  53. data/lib/graphql/schema/union.rb +0 -16
  54. data/lib/graphql/schema/warden.rb +1 -1
  55. data/lib/graphql/schema/wrapper.rb +0 -5
  56. data/lib/graphql/schema.rb +106 -944
  57. data/lib/graphql/static_validation/base_visitor.rb +4 -21
  58. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
  59. data/lib/graphql/static_validation/validator.rb +2 -24
  60. data/lib/graphql/static_validation.rb +0 -2
  61. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
  62. data/lib/graphql/subscriptions/event.rb +1 -1
  63. data/lib/graphql/subscriptions/instrumentation.rb +0 -51
  64. data/lib/graphql/subscriptions.rb +4 -13
  65. data/lib/graphql/tracing/platform_tracing.rb +0 -23
  66. data/lib/graphql/tracing.rb +0 -1
  67. data/lib/graphql/types/relay/connection_behaviors.rb +2 -6
  68. data/lib/graphql/types/relay/default_relay.rb +0 -10
  69. data/lib/graphql/types/relay/node_behaviors.rb +5 -1
  70. data/lib/graphql/types/relay.rb +0 -2
  71. data/lib/graphql/version.rb +1 -1
  72. data/lib/graphql.rb +1 -65
  73. metadata +2 -127
  74. data/lib/graphql/analysis/analyze_query.rb +0 -98
  75. data/lib/graphql/analysis/field_usage.rb +0 -45
  76. data/lib/graphql/analysis/max_query_complexity.rb +0 -26
  77. data/lib/graphql/analysis/max_query_depth.rb +0 -26
  78. data/lib/graphql/analysis/query_complexity.rb +0 -88
  79. data/lib/graphql/analysis/query_depth.rb +0 -43
  80. data/lib/graphql/analysis/reducer_state.rb +0 -48
  81. data/lib/graphql/argument.rb +0 -131
  82. data/lib/graphql/authorization.rb +0 -82
  83. data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
  84. data/lib/graphql/backwards_compatibility.rb +0 -61
  85. data/lib/graphql/base_type.rb +0 -232
  86. data/lib/graphql/boolean_type.rb +0 -2
  87. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
  88. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
  89. data/lib/graphql/compatibility/execution_specification.rb +0 -436
  90. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
  91. data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
  92. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
  93. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
  94. data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
  95. data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
  96. data/lib/graphql/compatibility.rb +0 -5
  97. data/lib/graphql/define/assign_argument.rb +0 -12
  98. data/lib/graphql/define/assign_connection.rb +0 -13
  99. data/lib/graphql/define/assign_enum_value.rb +0 -18
  100. data/lib/graphql/define/assign_global_id_field.rb +0 -11
  101. data/lib/graphql/define/assign_mutation_function.rb +0 -34
  102. data/lib/graphql/define/assign_object_field.rb +0 -42
  103. data/lib/graphql/define/defined_object_proxy.rb +0 -53
  104. data/lib/graphql/define/instance_definable.rb +0 -240
  105. data/lib/graphql/define/no_definition_error.rb +0 -7
  106. data/lib/graphql/define/non_null_with_bang.rb +0 -16
  107. data/lib/graphql/define/type_definer.rb +0 -31
  108. data/lib/graphql/define.rb +0 -31
  109. data/lib/graphql/deprecated_dsl.rb +0 -55
  110. data/lib/graphql/directive/deprecated_directive.rb +0 -2
  111. data/lib/graphql/directive/include_directive.rb +0 -2
  112. data/lib/graphql/directive/skip_directive.rb +0 -2
  113. data/lib/graphql/directive.rb +0 -107
  114. data/lib/graphql/enum_type.rb +0 -133
  115. data/lib/graphql/execution/execute.rb +0 -333
  116. data/lib/graphql/execution/flatten.rb +0 -40
  117. data/lib/graphql/execution/typecast.rb +0 -50
  118. data/lib/graphql/field/resolve.rb +0 -59
  119. data/lib/graphql/field.rb +0 -226
  120. data/lib/graphql/float_type.rb +0 -2
  121. data/lib/graphql/function.rb +0 -128
  122. data/lib/graphql/id_type.rb +0 -2
  123. data/lib/graphql/input_object_type.rb +0 -138
  124. data/lib/graphql/int_type.rb +0 -2
  125. data/lib/graphql/interface_type.rb +0 -72
  126. data/lib/graphql/internal_representation/document.rb +0 -27
  127. data/lib/graphql/internal_representation/node.rb +0 -206
  128. data/lib/graphql/internal_representation/print.rb +0 -51
  129. data/lib/graphql/internal_representation/rewrite.rb +0 -184
  130. data/lib/graphql/internal_representation/scope.rb +0 -88
  131. data/lib/graphql/internal_representation/visit.rb +0 -36
  132. data/lib/graphql/internal_representation.rb +0 -7
  133. data/lib/graphql/list_type.rb +0 -80
  134. data/lib/graphql/non_null_type.rb +0 -71
  135. data/lib/graphql/object_type.rb +0 -130
  136. data/lib/graphql/query/arguments.rb +0 -189
  137. data/lib/graphql/query/arguments_cache.rb +0 -24
  138. data/lib/graphql/query/executor.rb +0 -52
  139. data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
  140. data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
  141. data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
  142. data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
  143. data/lib/graphql/query/serial_execution.rb +0 -40
  144. data/lib/graphql/relay/array_connection.rb +0 -83
  145. data/lib/graphql/relay/base_connection.rb +0 -189
  146. data/lib/graphql/relay/connection_instrumentation.rb +0 -54
  147. data/lib/graphql/relay/connection_resolve.rb +0 -43
  148. data/lib/graphql/relay/connection_type.rb +0 -54
  149. data/lib/graphql/relay/edge.rb +0 -27
  150. data/lib/graphql/relay/edge_type.rb +0 -19
  151. data/lib/graphql/relay/edges_instrumentation.rb +0 -39
  152. data/lib/graphql/relay/global_id_resolve.rb +0 -17
  153. data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
  154. data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
  155. data/lib/graphql/relay/mutation/resolve.rb +0 -56
  156. data/lib/graphql/relay/mutation/result.rb +0 -38
  157. data/lib/graphql/relay/mutation.rb +0 -106
  158. data/lib/graphql/relay/node.rb +0 -39
  159. data/lib/graphql/relay/page_info.rb +0 -7
  160. data/lib/graphql/relay/relation_connection.rb +0 -188
  161. data/lib/graphql/relay/type_extensions.rb +0 -32
  162. data/lib/graphql/scalar_type.rb +0 -91
  163. data/lib/graphql/schema/catchall_middleware.rb +0 -35
  164. data/lib/graphql/schema/default_parse_error.rb +0 -10
  165. data/lib/graphql/schema/default_type_error.rb +0 -17
  166. data/lib/graphql/schema/member/accepts_definition.rb +0 -164
  167. data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
  168. data/lib/graphql/schema/member/instrumentation.rb +0 -131
  169. data/lib/graphql/schema/middleware_chain.rb +0 -82
  170. data/lib/graphql/schema/possible_types.rb +0 -44
  171. data/lib/graphql/schema/rescue_middleware.rb +0 -60
  172. data/lib/graphql/schema/timeout_middleware.rb +0 -88
  173. data/lib/graphql/schema/traversal.rb +0 -228
  174. data/lib/graphql/schema/validation.rb +0 -313
  175. data/lib/graphql/static_validation/default_visitor.rb +0 -15
  176. data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
  177. data/lib/graphql/string_type.rb +0 -2
  178. data/lib/graphql/subscriptions/subscription_root.rb +0 -76
  179. data/lib/graphql/tracing/skylight_tracing.rb +0 -70
  180. data/lib/graphql/types/relay/node_field.rb +0 -24
  181. data/lib/graphql/types/relay/nodes_field.rb +0 -43
  182. data/lib/graphql/union_type.rb +0 -115
  183. data/lib/graphql/upgrader/member.rb +0 -937
  184. data/lib/graphql/upgrader/schema.rb +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f0c0383f875c956752600647f437e48e61308c8f69384f8743ef91340c8e32a
4
- data.tar.gz: d6253ec483446638d4cb699b8f4375937166b46325b56f89566b7f8475f68b76
3
+ metadata.gz: c54b2619d5d111575839ba3e5d34794d993cb37a0b9aee4d41347551bb6be846
4
+ data.tar.gz: f6d53678c268767478a2a86ec34c045ab8744f4ea6f97deeebed3708df634340
5
5
  SHA512:
6
- metadata.gz: 969ab4479ebbe513ca239d9713711885dea4285eaf0256ec6d8a39bf4799cd8c489f7ba041d303a4ee6143cd847f592fa94e95c4f9a9655af714bd1e1daedf98
7
- data.tar.gz: 5f8e5be245480970e62e7713989ba2170171c824682214b740481be02ccf6e8a8f2cd0f317ed2cf9154328115d65ba06569c576231634aea8909452577d84902
6
+ metadata.gz: c7ccf09ae0a94e0cdce47f66555681391ac29af9cb544b662e8f9cd127905cda5cf5923dc64500dcab15899c7c51d5d2458ae78b95cb40ca47b1ce792e35f52c
7
+ data.tar.gz: ba6d04f4fc107fe9e2daaf70bd06288f85a6ead011764ab1b975e1796e97fa8c289cc08186bbf23c6020670a585c1a48c22d2acbd28ed10c6ec09b97f07a2a47
@@ -5,7 +5,7 @@ module GraphQL
5
5
  module AST
6
6
  class QueryComplexity < Analyzer
7
7
  # State for the query complexity calculation:
8
- # - `complexities_on_type` holds complexity scores for each type in an IRep node
8
+ # - `complexities_on_type` holds complexity scores for each type
9
9
  def initialize(query)
10
10
  super
11
11
  @complexities_on_type_by_query = {}
@@ -15,7 +15,6 @@ module GraphQL
15
15
  # # In your Schema file:
16
16
  #
17
17
  # class MySchema < GraphQL::Schema
18
- # use GraphQL::Analysis::AST
19
18
  # query_analyzer LogQueryDepth
20
19
  # end
21
20
  #
@@ -43,7 +43,7 @@ module GraphQL
43
43
 
44
44
  # Visit Helpers
45
45
 
46
- # @return [GraphQL::Query::Arguments] Arguments for this node, merging default values, literal values and query variables
46
+ # @return [GraphQL::Execution::Interpreter::Arguments] Arguments for this node, merging default values, literal values and query variables
47
47
  # @see {GraphQL::Query#arguments_for}
48
48
  def arguments_for(ast_node, field_definition)
49
49
  @query.arguments_for(ast_node, field_definition)
@@ -11,16 +11,6 @@ module GraphQL
11
11
  module Analysis
12
12
  module AST
13
13
  module_function
14
-
15
- def use(schema_class)
16
- if schema_class.analysis_engine == self
17
- definition_line = caller(2, 1).first
18
- GraphQL::Deprecation.warn("GraphQL::Analysis::AST is now the default; remove `use GraphQL::Analysis::AST` from the schema definition (#{definition_line})")
19
- else
20
- schema_class.analysis_engine = self
21
- end
22
- end
23
-
24
14
  # Analyze a multiplex, and all queries within.
25
15
  # Multiplex analyzers are ran for all queries, keeping state.
26
16
  # Query analyzers are ran per query, without carrying state between queries.
@@ -1,9 +1,2 @@
1
1
  # frozen_string_literal: true
2
2
  require "graphql/analysis/ast"
3
- require "graphql/analysis/max_query_complexity"
4
- require "graphql/analysis/max_query_depth"
5
- require "graphql/analysis/query_complexity"
6
- require "graphql/analysis/query_depth"
7
- require "graphql/analysis/reducer_state"
8
- require "graphql/analysis/analyze_query"
9
- require "graphql/analysis/field_usage"
@@ -97,24 +97,6 @@ module GraphQL
97
97
  else
98
98
  rows
99
99
  end
100
- when GraphQL::Query::Context::FieldResolutionContext
101
- ctx = context_entry
102
- field_name = "#{ctx.irep_node.owner_type.name}.#{ctx.field.name}"
103
- position = "#{ctx.ast_node.line}:#{ctx.ast_node.col}"
104
- field_alias = ctx.ast_node.alias
105
- object = ctx.object
106
- if object.is_a?(GraphQL::Schema::Object)
107
- object = object.object
108
- end
109
- rows << [
110
- "#{position}",
111
- "#{field_name}#{field_alias ? " as #{field_alias}" : ""}",
112
- "#{object.inspect}",
113
- ctx.irep_node.arguments.to_h.inspect,
114
- Backtrace::InspectResult.inspect_result(top && @override_value ? @override_value : ctx.value),
115
- ]
116
-
117
- build_rows(ctx.parent, rows: rows)
118
100
  when GraphQL::Query::Context
119
101
  query = context_entry.query
120
102
  op = query.selected_operation
@@ -23,7 +23,7 @@ module GraphQL
23
23
  push_data = multiplex.queries.first
24
24
  end
25
25
  when "execute_field", "execute_field_lazy"
26
- query = metadata[:query] || raise(ArgumentError, "Add `legacy: true` to use GraphQL::Backtrace without the interpreter runtime.")
26
+ query = metadata[:query]
27
27
  multiplex = query.multiplex
28
28
  push_key = metadata[:path]
29
29
  parent_frame = multiplex.context[:graphql_backtrace_contexts][push_key[0..-2]]
@@ -62,7 +62,6 @@ module GraphQL
62
62
  potential_context = multiplex_context[:last_graphql_backtrace_context]
63
63
 
64
64
  if potential_context.is_a?(GraphQL::Query::Context) ||
65
- potential_context.is_a?(GraphQL::Query::Context::FieldResolutionContext) ||
66
65
  potential_context.is_a?(Backtrace::Frame)
67
66
  raise TracedError.new(err, potential_context)
68
67
  else
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  require "graphql/backtrace/inspect_result"
3
- require "graphql/backtrace/legacy_tracer"
4
3
  require "graphql/backtrace/table"
5
4
  require "graphql/backtrace/traced_error"
6
5
  require "graphql/backtrace/tracer"
@@ -23,13 +22,8 @@ module GraphQL
23
22
 
24
23
  def_delegators :to_a, :each, :[]
25
24
 
26
- def self.use(schema_defn, legacy: false)
27
- tracer = if legacy
28
- self::LegacyTracer
29
- else
30
- self::Tracer
31
- end
32
- schema_defn.tracer(tracer)
25
+ def self.use(schema_defn)
26
+ schema_defn.tracer(self::Tracer)
33
27
  end
34
28
 
35
29
  def initialize(context, value: nil)
data/lib/graphql/dig.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  module GraphQL
3
3
  module Dig
4
4
  # implemented using the old activesupport #dig instead of the ruby built-in
5
- # so we can use some of the magic in Schema::InputObject and Query::Arguments
5
+ # so we can use some of the magic in Schema::InputObject and Interpreter::Arguments
6
6
  # to handle stringified/symbolized keys.
7
7
  #
8
8
  # @param args [Array<[String, Symbol>] Retrieves the value object corresponding to the each key objects repeatedly
@@ -2,14 +2,11 @@
2
2
 
3
3
  module GraphQL
4
4
  module Execution
5
- # A plugin that wraps query execution with error handling.
6
- # Supports class-based schemas and the new {Interpreter} runtime only.
5
+ # A plugin that wraps query execution with error handling. Installed by default.
7
6
  #
8
7
  # @example Handling ActiveRecord::NotFound
9
8
  #
10
9
  # class MySchema < GraphQL::Schema
11
- # use GraphQL::Execution::Errors
12
- #
13
10
  # rescue_from(ActiveRecord::NotFound) do |err, obj, args, ctx, field|
14
11
  # ErrorTracker.log("Not Found: #{err.message}")
15
12
  # nil
@@ -17,11 +14,6 @@ module GraphQL
17
14
  # end
18
15
  #
19
16
  class Errors
20
- def self.use(schema)
21
- definition_line = caller(2, 1).first
22
- GraphQL::Deprecation.warn("GraphQL::Execution::Errors is now installed by default, remove `use GraphQL::Execution::Errors` from #{definition_line}")
23
- end
24
-
25
17
  NEW_HANDLER_HASH = ->(h, k) {
26
18
  h[k] = {
27
19
  class: k,
@@ -472,10 +472,6 @@ module GraphQL
472
472
  # Use this flag to tell Interpreter::Arguments to add itself
473
473
  # to the keyword args hash _before_ freezing everything.
474
474
  extra_args[:argument_details] = :__arguments_add_self
475
- when :irep_node
476
- # This is used by `__typename` in order to support the legacy runtime,
477
- # but it has no use here (and it's always `nil`).
478
- # Stop adding it here to avoid the overhead of `.merge_extras` below.
479
475
  when :parent
480
476
  extra_args[:parent] = parent_object
481
477
  else
@@ -619,7 +615,7 @@ module GraphQL
619
615
  err
620
616
  end
621
617
  continue_value(path, next_value, parent_type, field, is_non_null, ast_node, result_name, selection_result)
622
- elsif GraphQL::Execution::Execute::SKIP == value
618
+ elsif GraphQL::Execution::SKIP == value
623
619
  # It's possible a lazy was already written here
624
620
  case selection_result
625
621
  when GraphQLResultHash
@@ -819,9 +815,6 @@ module GraphQL
819
815
  yield
820
816
  else
821
817
  dir_defn = @schema_directives.fetch(dir_node.name)
822
- if !dir_defn.is_a?(Class)
823
- dir_defn = dir_defn.type_class || raise("Only class-based directives are supported (not `@#{dir_node.name}`)")
824
- end
825
818
  raw_dir_args = arguments(nil, dir_defn, dir_node)
826
819
  dir_args = continue_value(
827
820
  @context[:current_path], # path
@@ -847,7 +840,7 @@ module GraphQL
847
840
  # Check {Schema::Directive.include?} for each directive that's present
848
841
  def directives_include?(node, graphql_object, parent_type)
849
842
  node.directives.each do |dir_node|
850
- dir_defn = @schema_directives.fetch(dir_node.name).type_class || raise("Only class-based directives are supported (not #{dir_node.name.inspect})")
843
+ dir_defn = @schema_directives.fetch(dir_node.name)
851
844
  args = arguments(graphql_object, dir_defn, dir_node)
852
845
  if !dir_defn.include?(graphql_object, args, context)
853
846
  return false
@@ -11,28 +11,6 @@ require "graphql/execution/interpreter/handles_raw_value"
11
11
  module GraphQL
12
12
  module Execution
13
13
  class Interpreter
14
- def initialize
15
- end
16
-
17
- # Support `Executor` :S
18
- def execute(_operation, _root_type, query)
19
- runtime = evaluate(query)
20
- sync_lazies(query: query)
21
- runtime.final_result
22
- end
23
-
24
- def self.use(schema_class)
25
- if schema_class.interpreter?
26
- definition_line = caller(2, 1).first
27
- GraphQL::Deprecation.warn("GraphQL::Execution::Interpreter is now the default; remove `use GraphQL::Execution::Interpreter` from the schema definition (#{definition_line})")
28
- else
29
- schema_class.query_execution_strategy(self)
30
- schema_class.mutation_execution_strategy(self)
31
- schema_class.subscription_execution_strategy(self)
32
- schema_class.add_subscription_extension_if_necessary
33
- end
34
- end
35
-
36
14
  def self.begin_multiplex(multiplex)
37
15
  # Since this is basically the batching context,
38
16
  # share it for a whole multiplex
@@ -52,7 +52,7 @@ module GraphQL
52
52
  # (fewer clauses in a hot `case` block), but now it requires special handling here.
53
53
  # I think it's still worth it for the performance win, but if the number of special
54
54
  # cases grows, then maybe it's worth rethinking somehow.
55
- if @value.is_a?(StandardError) && @value != GraphQL::Execution::Execute::SKIP
55
+ if @value.is_a?(StandardError) && @value != GraphQL::Execution::SKIP
56
56
  raise @value
57
57
  else
58
58
  @value
@@ -91,7 +91,7 @@ module GraphQL
91
91
  def selection(field_name, selected_type: @selected_type, arguments: nil)
92
92
  next_field_name = normalize_name(field_name)
93
93
 
94
- next_field_defn = get_class_based_field(selected_type, next_field_name)
94
+ next_field_defn = @query.get_field(selected_type, next_field_name)
95
95
  if next_field_defn
96
96
  next_nodes = []
97
97
  @ast_nodes.each do |ast_node|
@@ -137,7 +137,7 @@ module GraphQL
137
137
 
138
138
  subselections_by_type.each do |type, ast_nodes_by_response_key|
139
139
  ast_nodes_by_response_key.each do |response_key, ast_nodes|
140
- field_defn = get_class_based_field(type, ast_nodes.first.name)
140
+ field_defn = @query.get_field(type, ast_nodes.first.name)
141
141
  lookahead = Lookahead.new(query: @query, ast_nodes: ast_nodes, field: field_defn, owner_type: type)
142
142
  subselections.push(lookahead)
143
143
  end
@@ -213,17 +213,10 @@ module GraphQL
213
213
  end
214
214
  end
215
215
 
216
- # Wrap get_field and ensure that it returns a GraphQL::Schema::Field.
217
- # Remove this when legacy execution is removed.
218
- def get_class_based_field(type, name)
219
- f = @query.get_field(type, name)
220
- f && f.type_class
221
- end
222
-
223
216
  def skipped_by_directive?(ast_selection)
224
217
  ast_selection.directives.each do |directive|
225
218
  dir_defn = @query.schema.directives.fetch(directive.name)
226
- directive_class = dir_defn.type_class
219
+ directive_class = dir_defn
227
220
  if directive_class
228
221
  dir_args = @query.arguments_for(directive, dir_defn)
229
222
  return true unless directive_class.static_include?(dir_args, @query.context)
@@ -244,7 +237,7 @@ module GraphQL
244
237
  elsif arguments.nil? || arguments.empty?
245
238
  selections_on_type[response_key] = [ast_selection]
246
239
  else
247
- field_defn = get_class_based_field(selected_type, ast_selection.name)
240
+ field_defn = @query.get_field(selected_type, ast_selection.name)
248
241
  if arguments_match?(arguments, field_defn, ast_selection)
249
242
  selections_on_type[response_key] = [ast_selection]
250
243
  end
@@ -254,14 +247,14 @@ module GraphQL
254
247
  subselections_on_type = selections_on_type
255
248
  if (t = ast_selection.type)
256
249
  # Assuming this is valid, that `t` will be found.
257
- on_type = @query.get_type(t.name).type_class
250
+ on_type = @query.get_type(t.name)
258
251
  subselections_on_type = subselections_by_type[on_type] ||= {}
259
252
  end
260
253
  find_selections(subselections_by_type, subselections_on_type, on_type, ast_selection.selections, arguments)
261
254
  when GraphQL::Language::Nodes::FragmentSpread
262
255
  frag_defn = @query.fragments[ast_selection.name] || raise("Invariant: Can't look ahead to nonexistent fragment #{ast_selection.name} (found: #{@query.fragments.keys})")
263
256
  # Again, assuming a valid AST
264
- on_type = @query.get_type(frag_defn.type.name).type_class
257
+ on_type = @query.get_type(frag_defn.type.name)
265
258
  subselections_on_type = subselections_by_type[on_type] ||= {}
266
259
  find_selections(subselections_by_type, subselections_on_type, on_type, frag_defn.selections, arguments)
267
260
  else
@@ -45,30 +45,64 @@ module GraphQL
45
45
  end
46
46
 
47
47
  class << self
48
- def run_all(schema, query_options, **kwargs)
49
- queries = query_options.map { |opts| GraphQL::Query.new(schema, nil, **opts) }
50
- run_queries(schema, queries, **kwargs)
51
- end
52
-
53
48
  # @param schema [GraphQL::Schema]
54
- # @param queries [Array<GraphQL::Query>]
49
+ # @param queries [Array<GraphQL::Query, Hash>]
55
50
  # @param context [Hash]
56
51
  # @param max_complexity [Integer, nil]
57
52
  # @return [Array<Hash>] One result per query
58
- def run_queries(schema, queries, context: {}, max_complexity: schema.max_complexity)
53
+ def run_all(schema, query_options, context: {}, max_complexity: schema.max_complexity)
54
+ queries = query_options.map do |opts|
55
+ case opts
56
+ when Hash
57
+ GraphQL::Query.new(schema, nil, **opts)
58
+ when GraphQL::Query
59
+ opts
60
+ else
61
+ raise "Expected Hash or GraphQL::Query, not #{opts.class} (#{opts.inspect})"
62
+ end
63
+ end
64
+
59
65
  multiplex = self.new(schema: schema, queries: queries, context: context, max_complexity: max_complexity)
60
66
  multiplex.trace("execute_multiplex", { multiplex: multiplex }) do
61
- if supports_multiplexing?(schema)
62
- instrument_and_analyze(multiplex) do
63
- run_as_multiplex(multiplex)
67
+ GraphQL::Execution::Instrumentation.apply_instrumenters(multiplex) do
68
+ schema = multiplex.schema
69
+ multiplex_analyzers = schema.multiplex_analyzers
70
+ if multiplex.max_complexity
71
+ multiplex_analyzers += [GraphQL::Analysis::AST::MaxQueryComplexity]
64
72
  end
65
- else
66
- if queries.length != 1
67
- raise ArgumentError, "Multiplexing doesn't support custom execution strategies, run one query at a time instead"
68
- else
69
- instrument_and_analyze(multiplex) do
70
- [run_one_legacy(schema, queries.first)]
73
+
74
+ schema.analysis_engine.analyze_multiplex(multiplex, multiplex_analyzers)
75
+
76
+ begin
77
+ multiplex.schema.query_execution_strategy.begin_multiplex(multiplex)
78
+ # Do as much eager evaluation of the query as possible
79
+ results = []
80
+ queries.each_with_index do |query, idx|
81
+ multiplex.dataloader.append_job { begin_query(results, idx, query, multiplex) }
71
82
  end
83
+
84
+ multiplex.dataloader.run
85
+
86
+ # Then, work through lazy results in a breadth-first way
87
+ multiplex.dataloader.append_job {
88
+ multiplex.schema.query_execution_strategy.finish_multiplex(results, multiplex)
89
+ }
90
+ multiplex.dataloader.run
91
+
92
+ # Then, find all errors and assign the result to the query object
93
+ results.each_with_index do |data_result, idx|
94
+ query = queries[idx]
95
+ finish_query(data_result, query, multiplex)
96
+ # Get the Query::Result, not the Hash
97
+ results[idx] = query.result
98
+ end
99
+
100
+ results
101
+ rescue Exception
102
+ # TODO rescue at a higher level so it will catch errors in analysis, too
103
+ # Assign values here so that the query's `@executed` becomes true
104
+ queries.map { |q| q.result_values ||= {} }
105
+ raise
72
106
  end
73
107
  end
74
108
  end
@@ -81,7 +115,6 @@ module GraphQL
81
115
  NO_OPERATION
82
116
  else
83
117
  begin
84
- # These were checked to be the same in `#supports_multiplexing?`
85
118
  query.schema.query_execution_strategy.begin_query(query, multiplex)
86
119
  rescue GraphQL::ExecutionError => err
87
120
  query.context.errors << err
@@ -94,40 +127,6 @@ module GraphQL
94
127
 
95
128
  private
96
129
 
97
- def run_as_multiplex(multiplex)
98
-
99
- multiplex.schema.query_execution_strategy.begin_multiplex(multiplex)
100
- queries = multiplex.queries
101
- # Do as much eager evaluation of the query as possible
102
- results = []
103
- queries.each_with_index do |query, idx|
104
- multiplex.dataloader.append_job { begin_query(results, idx, query, multiplex) }
105
- end
106
-
107
- multiplex.dataloader.run
108
-
109
- # Then, work through lazy results in a breadth-first way
110
- multiplex.dataloader.append_job {
111
- multiplex.schema.query_execution_strategy.finish_multiplex(results, multiplex)
112
- }
113
- multiplex.dataloader.run
114
-
115
- # Then, find all errors and assign the result to the query object
116
- results.each_with_index do |data_result, idx|
117
- query = queries[idx]
118
- finish_query(data_result, query, multiplex)
119
- # Get the Query::Result, not the Hash
120
- results[idx] = query.result
121
- end
122
-
123
- results
124
- rescue Exception
125
- # TODO rescue at a higher level so it will catch errors in analysis, too
126
- # Assign values here so that the query's `@executed` becomes true
127
- queries.map { |q| q.result_values ||= {} }
128
- raise
129
- end
130
-
131
130
  # @param data_result [Hash] The result for the "data" key, if any
132
131
  # @param query [GraphQL::Query] The query which was run
133
132
  # @return [Hash] final result of this query, including all values and errors
@@ -155,62 +154,6 @@ module GraphQL
155
154
  query.result_values["extensions"] = query.context.namespace(:__query_result_extensions__)
156
155
  end
157
156
  end
158
-
159
- # use the old `query_execution_strategy` etc to run this query
160
- def run_one_legacy(schema, query)
161
- GraphQL::Deprecation.warn "Multiplex.run_one_legacy will be removed from GraphQL-Ruby 2.0, upgrade to the Interpreter to avoid this deprecated codepath: https://graphql-ruby.org/queries/interpreter.html"
162
-
163
- query.result_values = if !query.valid?
164
- all_errors = query.validation_errors + query.analysis_errors + query.context.errors
165
- if all_errors.any?
166
- { "errors" => all_errors.map(&:to_h) }
167
- else
168
- nil
169
- end
170
- else
171
- GraphQL::Query::Executor.new(query).result
172
- end
173
- end
174
-
175
- DEFAULT_STRATEGIES = [
176
- GraphQL::Execution::Execute,
177
- GraphQL::Execution::Interpreter
178
- ]
179
- # @return [Boolean] True if the schema is only using one strategy, and it's one that supports multiplexing.
180
- def supports_multiplexing?(schema)
181
- schema_strategies = [schema.query_execution_strategy, schema.mutation_execution_strategy, schema.subscription_execution_strategy]
182
- schema_strategies.uniq!
183
- schema_strategies.size == 1 && DEFAULT_STRATEGIES.include?(schema_strategies.first)
184
- end
185
-
186
- # Apply multiplex & query instrumentation to `queries`.
187
- #
188
- # It yields when the queries should be executed, then runs teardown.
189
- def instrument_and_analyze(multiplex)
190
- GraphQL::Execution::Instrumentation.apply_instrumenters(multiplex) do
191
- schema = multiplex.schema
192
- if schema.interpreter? && schema.analysis_engine != GraphQL::Analysis::AST
193
- raise <<-ERR
194
- Can't use `GraphQL::Execution::Interpreter` without `GraphQL::Analysis::AST`, please add this plugin to your schema:
195
-
196
- use GraphQL::Analysis::AST
197
-
198
- For information about the new analysis engine: https://graphql-ruby.org/queries/ast_analysis.html
199
- ERR
200
- end
201
- multiplex_analyzers = schema.multiplex_analyzers
202
- if multiplex.max_complexity
203
- multiplex_analyzers += if schema.using_ast_analysis?
204
- [GraphQL::Analysis::AST::MaxQueryComplexity]
205
- else
206
- [GraphQL::Analysis::MaxQueryComplexity.new(multiplex.max_complexity)]
207
- end
208
- end
209
-
210
- schema.analysis_engine.analyze_multiplex(multiplex, multiplex_analyzers)
211
- yield
212
- end
213
- end
214
157
  end
215
158
  end
216
159
  end
@@ -1,11 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
  require "graphql/execution/directive_checks"
3
- require "graphql/execution/execute"
4
- require "graphql/execution/flatten"
5
3
  require "graphql/execution/instrumentation"
6
4
  require "graphql/execution/interpreter"
7
5
  require "graphql/execution/lazy"
8
6
  require "graphql/execution/lookahead"
9
7
  require "graphql/execution/multiplex"
10
- require "graphql/execution/typecast"
11
8
  require "graphql/execution/errors"
9
+
10
+ module GraphQL
11
+ module Execution
12
+ # @api private
13
+ class Skip < GraphQL::Error; end
14
+
15
+ # Just a singleton for implementing {Query::Context#skip}
16
+ # @api private
17
+ SKIP = Skip.new
18
+ end
19
+ end
@@ -2,15 +2,10 @@
2
2
  module GraphQL
3
3
  module Introspection
4
4
  class DynamicFields < Introspection::BaseObject
5
- field :__typename, String, "The name of this type", null: false, extras: [:irep_node]
5
+ field :__typename, String, "The name of this type", null: false
6
6
 
7
- # `irep_node:` will be nil for the interpreter, since there is no such thing
8
- def __typename(irep_node: nil)
9
- if context.interpreter?
10
- object.class.graphql_name
11
- else
12
- irep_node.owner_type.name
13
- end
7
+ def __typename
8
+ object.class.graphql_name
14
9
  end
15
10
  end
16
11
  end
@@ -11,24 +11,11 @@ module GraphQL
11
11
  # Apply wrapping manually since this field isn't wrapped by instrumentation
12
12
  schema = @context.query.schema
13
13
  schema_type = schema.introspection_system.types["__Schema"]
14
- schema_type.type_class.authorized_new(schema, @context)
14
+ schema_type.authorized_new(schema, @context)
15
15
  end
16
16
 
17
17
  def __type(name:)
18
- return unless context.warden.reachable_type?(name)
19
- type = context.warden.get_type(name)
20
-
21
- if type && context.interpreter? && !type.is_a?(Module)
22
- type = type.type_class || raise("Invariant: interpreter requires class-based type for #{name}")
23
- end
24
-
25
- # The interpreter provides this wrapping, other execution doesnt, so support both.
26
- if type && !context.interpreter?
27
- # Apply wrapping manually since this field isn't wrapped by instrumentation
28
- type_type = context.schema.introspection_system.types["__Type"]
29
- type = type_type.type_class.authorized_new(type, context)
30
- end
31
- type
18
+ context.warden.reachable_type?(name) ? context.warden.get_type(name) : nil
32
19
  end
33
20
  end
34
21
  end
@@ -321,23 +321,6 @@ module GraphQL
321
321
  end
322
322
  end
323
323
 
324
- # This is just for printing legacy `.define { ... }` schemas, where `deprecation_reason` isn't added to `.directives`.
325
- if !member.respond_to?(:directives) && member.respond_to?(:deprecation_reason) && (reason = member.deprecation_reason)
326
- arguments = []
327
-
328
- if reason != GraphQL::Schema::Directive::DEFAULT_DEPRECATION_REASON
329
- arguments << GraphQL::Language::Nodes::Argument.new(
330
- name: "reason",
331
- value: reason
332
- )
333
- end
334
-
335
- dirs << GraphQL::Language::Nodes::Directive.new(
336
- name: GraphQL::Directive::DeprecatedDirective.graphql_name,
337
- arguments: arguments
338
- )
339
- end
340
-
341
324
  dirs
342
325
  end
343
326
 
@@ -21,13 +21,6 @@ module GraphQL
21
21
  class ImplementationMissingError < GraphQL::Error
22
22
  end
23
23
 
24
- def self.use(schema_defn)
25
- if schema_defn.plugins.any? { |(plugin, args)| plugin == self }
26
- GraphQL::Deprecation.warn("#{self} is now the default, remove `use #{self}` from #{caller(2,1).first}")
27
- end
28
- schema_defn.connections = self.new(schema: schema_defn)
29
- end
30
-
31
24
  def initialize(schema:)
32
25
  @schema = schema
33
26
  @wrappers = {}
@@ -85,26 +78,7 @@ module GraphQL
85
78
  edge_class: edge_class_for_field(field),
86
79
  )
87
80
  else
88
- begin
89
- connection_class = GraphQL::Relay::BaseConnection.connection_for_nodes(items)
90
- if parent.is_a?(GraphQL::Schema::Object)
91
- parent = parent.object
92
- end
93
- connection_class.new(
94
- items,
95
- arguments,
96
- field: field,
97
- max_page_size: field.max_page_size,
98
- parent: parent,
99
- context: context,
100
- )
101
- rescue RuntimeError => err
102
- if err.message.include?("No connection implementation to wrap")
103
- raise ImplementationMissingError, "Couldn't find a connection wrapper for #{items.class} during #{field.path} (#{items.inspect})"
104
- else
105
- raise err
106
- end
107
- end
81
+ raise ImplementationMissingError, "Couldn't find a connection wrapper for #{items.class} during #{field.path} (#{items.inspect})"
108
82
  end
109
83
  end
110
84
 
@@ -113,7 +87,7 @@ module GraphQL
113
87
  def edge_class_for_field(field)
114
88
  conn_type = field.type.unwrap
115
89
  conn_type_edge_type = conn_type.respond_to?(:edge_class) && conn_type.edge_class
116
- if conn_type_edge_type && conn_type_edge_type != Relay::Edge
90
+ if conn_type_edge_type && conn_type_edge_type != Pagination::Connection::Edge
117
91
  conn_type_edge_type
118
92
  else
119
93
  nil