graphql 1.13.6 → 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 (216) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/core.rb +0 -7
  3. data/lib/generators/graphql/enum_generator.rb +4 -10
  4. data/lib/generators/graphql/field_extractor.rb +31 -0
  5. data/lib/generators/graphql/input_generator.rb +50 -0
  6. data/lib/generators/graphql/install/mutation_root_generator.rb +34 -0
  7. data/lib/generators/graphql/{templates → install/templates}/base_mutation.erb +0 -0
  8. data/lib/generators/graphql/{templates → install/templates}/mutation_type.erb +0 -0
  9. data/lib/generators/graphql/install_generator.rb +1 -1
  10. data/lib/generators/graphql/interface_generator.rb +7 -7
  11. data/lib/generators/graphql/mutation_create_generator.rb +22 -0
  12. data/lib/generators/graphql/mutation_delete_generator.rb +22 -0
  13. data/lib/generators/graphql/mutation_generator.rb +5 -30
  14. data/lib/generators/graphql/mutation_update_generator.rb +22 -0
  15. data/lib/generators/graphql/object_generator.rb +8 -37
  16. data/lib/generators/graphql/orm_mutations_base.rb +40 -0
  17. data/lib/generators/graphql/scalar_generator.rb +4 -2
  18. data/lib/generators/graphql/templates/enum.erb +5 -1
  19. data/lib/generators/graphql/templates/input.erb +9 -0
  20. data/lib/generators/graphql/templates/interface.erb +4 -2
  21. data/lib/generators/graphql/templates/mutation.erb +1 -1
  22. data/lib/generators/graphql/templates/mutation_create.erb +20 -0
  23. data/lib/generators/graphql/templates/mutation_delete.erb +20 -0
  24. data/lib/generators/graphql/templates/mutation_update.erb +21 -0
  25. data/lib/generators/graphql/templates/object.erb +4 -2
  26. data/lib/generators/graphql/templates/scalar.erb +3 -1
  27. data/lib/generators/graphql/templates/union.erb +4 -2
  28. data/lib/generators/graphql/type_generator.rb +46 -9
  29. data/lib/generators/graphql/union_generator.rb +5 -5
  30. data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
  31. data/lib/graphql/analysis/ast/query_depth.rb +0 -1
  32. data/lib/graphql/analysis/ast/visitor.rb +3 -2
  33. data/lib/graphql/analysis/ast.rb +0 -10
  34. data/lib/graphql/analysis.rb +0 -7
  35. data/lib/graphql/backtrace/table.rb +0 -18
  36. data/lib/graphql/backtrace/tracer.rb +1 -2
  37. data/lib/graphql/backtrace.rb +2 -8
  38. data/lib/graphql/dataloader/source.rb +2 -2
  39. data/lib/graphql/dig.rb +1 -1
  40. data/lib/graphql/execution/errors.rb +1 -9
  41. data/lib/graphql/execution/interpreter/runtime.rb +2 -9
  42. data/lib/graphql/execution/interpreter.rb +0 -22
  43. data/lib/graphql/execution/lazy.rb +1 -1
  44. data/lib/graphql/execution/lookahead.rb +6 -13
  45. data/lib/graphql/execution/multiplex.rb +50 -107
  46. data/lib/graphql/execution.rb +11 -3
  47. data/lib/graphql/introspection/dynamic_fields.rb +3 -8
  48. data/lib/graphql/introspection/entry_points.rb +2 -15
  49. data/lib/graphql/introspection.rb +4 -4
  50. data/lib/graphql/language/document_from_schema_definition.rb +0 -17
  51. data/lib/graphql/pagination/connections.rb +2 -28
  52. data/lib/graphql/query/context.rb +1 -185
  53. data/lib/graphql/query/literal_input.rb +8 -13
  54. data/lib/graphql/query/validation_pipeline.rb +8 -37
  55. data/lib/graphql/query/variables.rb +22 -18
  56. data/lib/graphql/query.rb +5 -35
  57. data/lib/graphql/railtie.rb +0 -104
  58. data/lib/graphql/relay.rb +0 -15
  59. data/lib/graphql/rubocop/graphql/default_required_true.rb +4 -4
  60. data/lib/graphql/schema/addition.rb +1 -8
  61. data/lib/graphql/schema/argument.rb +18 -25
  62. data/lib/graphql/schema/build_from_definition.rb +0 -1
  63. data/lib/graphql/schema/directive.rb +4 -21
  64. data/lib/graphql/schema/enum.rb +1 -18
  65. data/lib/graphql/schema/enum_value.rb +0 -22
  66. data/lib/graphql/schema/field.rb +22 -194
  67. data/lib/graphql/schema/input_object.rb +10 -57
  68. data/lib/graphql/schema/interface.rb +0 -25
  69. data/lib/graphql/schema/introspection_system.rb +3 -8
  70. data/lib/graphql/schema/late_bound_type.rb +2 -2
  71. data/lib/graphql/schema/list.rb +0 -6
  72. data/lib/graphql/schema/loader.rb +0 -1
  73. data/lib/graphql/schema/member/base_dsl_methods.rb +0 -5
  74. data/lib/graphql/schema/member/build_type.rb +4 -6
  75. data/lib/graphql/schema/member/has_arguments.rb +14 -18
  76. data/lib/graphql/schema/member/has_fields.rb +2 -2
  77. data/lib/graphql/schema/member/has_interfaces.rb +0 -2
  78. data/lib/graphql/schema/member.rb +0 -6
  79. data/lib/graphql/schema/mutation.rb +0 -9
  80. data/lib/graphql/schema/non_null.rb +1 -7
  81. data/lib/graphql/schema/object.rb +0 -40
  82. data/lib/graphql/schema/relay_classic_mutation.rb +17 -28
  83. data/lib/graphql/schema/scalar.rb +0 -15
  84. data/lib/graphql/schema/union.rb +0 -16
  85. data/lib/graphql/schema/warden.rb +1 -1
  86. data/lib/graphql/schema/wrapper.rb +0 -5
  87. data/lib/graphql/schema.rb +107 -949
  88. data/lib/graphql/static_validation/base_visitor.rb +4 -21
  89. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
  90. data/lib/graphql/static_validation/validator.rb +2 -24
  91. data/lib/graphql/static_validation.rb +0 -2
  92. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
  93. data/lib/graphql/subscriptions/event.rb +1 -1
  94. data/lib/graphql/subscriptions/instrumentation.rb +0 -51
  95. data/lib/graphql/subscriptions.rb +4 -13
  96. data/lib/graphql/tracing/platform_tracing.rb +0 -23
  97. data/lib/graphql/tracing.rb +0 -1
  98. data/lib/graphql/types/iso_8601_date_time.rb +8 -1
  99. data/lib/graphql/types/relay/connection_behaviors.rb +4 -7
  100. data/lib/graphql/types/relay/default_relay.rb +0 -10
  101. data/lib/graphql/types/relay/node_behaviors.rb +5 -1
  102. data/lib/graphql/types/relay.rb +0 -2
  103. data/lib/graphql/version.rb +1 -1
  104. data/lib/graphql.rb +12 -65
  105. metadata +15 -129
  106. data/lib/graphql/analysis/analyze_query.rb +0 -98
  107. data/lib/graphql/analysis/field_usage.rb +0 -45
  108. data/lib/graphql/analysis/max_query_complexity.rb +0 -26
  109. data/lib/graphql/analysis/max_query_depth.rb +0 -26
  110. data/lib/graphql/analysis/query_complexity.rb +0 -88
  111. data/lib/graphql/analysis/query_depth.rb +0 -43
  112. data/lib/graphql/analysis/reducer_state.rb +0 -48
  113. data/lib/graphql/argument.rb +0 -131
  114. data/lib/graphql/authorization.rb +0 -82
  115. data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
  116. data/lib/graphql/backwards_compatibility.rb +0 -61
  117. data/lib/graphql/base_type.rb +0 -232
  118. data/lib/graphql/boolean_type.rb +0 -2
  119. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
  120. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
  121. data/lib/graphql/compatibility/execution_specification.rb +0 -436
  122. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
  123. data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
  124. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
  125. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
  126. data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
  127. data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
  128. data/lib/graphql/compatibility.rb +0 -5
  129. data/lib/graphql/define/assign_argument.rb +0 -12
  130. data/lib/graphql/define/assign_connection.rb +0 -13
  131. data/lib/graphql/define/assign_enum_value.rb +0 -18
  132. data/lib/graphql/define/assign_global_id_field.rb +0 -11
  133. data/lib/graphql/define/assign_mutation_function.rb +0 -34
  134. data/lib/graphql/define/assign_object_field.rb +0 -42
  135. data/lib/graphql/define/defined_object_proxy.rb +0 -53
  136. data/lib/graphql/define/instance_definable.rb +0 -240
  137. data/lib/graphql/define/no_definition_error.rb +0 -7
  138. data/lib/graphql/define/non_null_with_bang.rb +0 -16
  139. data/lib/graphql/define/type_definer.rb +0 -31
  140. data/lib/graphql/define.rb +0 -31
  141. data/lib/graphql/deprecated_dsl.rb +0 -55
  142. data/lib/graphql/directive/deprecated_directive.rb +0 -2
  143. data/lib/graphql/directive/include_directive.rb +0 -2
  144. data/lib/graphql/directive/skip_directive.rb +0 -2
  145. data/lib/graphql/directive.rb +0 -107
  146. data/lib/graphql/enum_type.rb +0 -133
  147. data/lib/graphql/execution/execute.rb +0 -333
  148. data/lib/graphql/execution/flatten.rb +0 -40
  149. data/lib/graphql/execution/typecast.rb +0 -50
  150. data/lib/graphql/field/resolve.rb +0 -59
  151. data/lib/graphql/field.rb +0 -226
  152. data/lib/graphql/float_type.rb +0 -2
  153. data/lib/graphql/function.rb +0 -128
  154. data/lib/graphql/id_type.rb +0 -2
  155. data/lib/graphql/input_object_type.rb +0 -138
  156. data/lib/graphql/int_type.rb +0 -2
  157. data/lib/graphql/interface_type.rb +0 -72
  158. data/lib/graphql/internal_representation/document.rb +0 -27
  159. data/lib/graphql/internal_representation/node.rb +0 -206
  160. data/lib/graphql/internal_representation/print.rb +0 -51
  161. data/lib/graphql/internal_representation/rewrite.rb +0 -184
  162. data/lib/graphql/internal_representation/scope.rb +0 -88
  163. data/lib/graphql/internal_representation/visit.rb +0 -36
  164. data/lib/graphql/internal_representation.rb +0 -7
  165. data/lib/graphql/list_type.rb +0 -80
  166. data/lib/graphql/non_null_type.rb +0 -71
  167. data/lib/graphql/object_type.rb +0 -130
  168. data/lib/graphql/query/arguments.rb +0 -189
  169. data/lib/graphql/query/arguments_cache.rb +0 -24
  170. data/lib/graphql/query/executor.rb +0 -52
  171. data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
  172. data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
  173. data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
  174. data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
  175. data/lib/graphql/query/serial_execution.rb +0 -40
  176. data/lib/graphql/relay/array_connection.rb +0 -83
  177. data/lib/graphql/relay/base_connection.rb +0 -189
  178. data/lib/graphql/relay/connection_instrumentation.rb +0 -54
  179. data/lib/graphql/relay/connection_resolve.rb +0 -43
  180. data/lib/graphql/relay/connection_type.rb +0 -41
  181. data/lib/graphql/relay/edge.rb +0 -27
  182. data/lib/graphql/relay/edge_type.rb +0 -19
  183. data/lib/graphql/relay/edges_instrumentation.rb +0 -39
  184. data/lib/graphql/relay/global_id_resolve.rb +0 -18
  185. data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
  186. data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
  187. data/lib/graphql/relay/mutation/resolve.rb +0 -56
  188. data/lib/graphql/relay/mutation/result.rb +0 -38
  189. data/lib/graphql/relay/mutation.rb +0 -106
  190. data/lib/graphql/relay/node.rb +0 -39
  191. data/lib/graphql/relay/page_info.rb +0 -7
  192. data/lib/graphql/relay/relation_connection.rb +0 -188
  193. data/lib/graphql/relay/type_extensions.rb +0 -32
  194. data/lib/graphql/scalar_type.rb +0 -91
  195. data/lib/graphql/schema/catchall_middleware.rb +0 -35
  196. data/lib/graphql/schema/default_parse_error.rb +0 -10
  197. data/lib/graphql/schema/default_type_error.rb +0 -17
  198. data/lib/graphql/schema/member/accepts_definition.rb +0 -164
  199. data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
  200. data/lib/graphql/schema/member/instrumentation.rb +0 -131
  201. data/lib/graphql/schema/middleware_chain.rb +0 -82
  202. data/lib/graphql/schema/possible_types.rb +0 -44
  203. data/lib/graphql/schema/rescue_middleware.rb +0 -60
  204. data/lib/graphql/schema/timeout_middleware.rb +0 -88
  205. data/lib/graphql/schema/traversal.rb +0 -228
  206. data/lib/graphql/schema/validation.rb +0 -313
  207. data/lib/graphql/static_validation/default_visitor.rb +0 -15
  208. data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
  209. data/lib/graphql/string_type.rb +0 -2
  210. data/lib/graphql/subscriptions/subscription_root.rb +0 -76
  211. data/lib/graphql/tracing/skylight_tracing.rb +0 -70
  212. data/lib/graphql/types/relay/node_field.rb +0 -24
  213. data/lib/graphql/types/relay/nodes_field.rb +0 -43
  214. data/lib/graphql/union_type.rb +0 -115
  215. data/lib/graphql/upgrader/member.rb +0 -937
  216. data/lib/graphql/upgrader/schema.rb +0 -38
@@ -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
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
3
  module Introspection
4
- def self.query(include_deprecated_args: false)
4
+ def self.query(include_deprecated_args: false, include_schema_description: false, include_is_repeatable: false, include_specified_by_url: false)
5
5
  # The introspection query to end all introspection queries, copied from
6
6
  # https://github.com/graphql/graphql-js/blob/master/src/utilities/introspectionQuery.js
7
7
  <<-QUERY
8
8
  query IntrospectionQuery {
9
9
  __schema {
10
- description
10
+ #{include_schema_description ? "description" : ""}
11
11
  queryType { name }
12
12
  mutationType { name }
13
13
  subscriptionType { name }
@@ -18,7 +18,7 @@ query IntrospectionQuery {
18
18
  name
19
19
  description
20
20
  locations
21
- isRepeatable
21
+ #{include_is_repeatable ? "isRepeatable" : ""}
22
22
  args#{include_deprecated_args ? '(includeDeprecated: true)' : ''} {
23
23
  ...InputValue
24
24
  }
@@ -29,7 +29,7 @@ fragment FullType on __Type {
29
29
  kind
30
30
  name
31
31
  description
32
- specifiedByUrl
32
+ #{include_specified_by_url ? "specifiedByUrl" : ""}
33
33
  fields(includeDeprecated: true) {
34
34
  name
35
35
  description
@@ -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
@@ -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,