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
@@ -5,8 +5,6 @@ require "graphql/schema/field/scope_extension"
5
5
  module GraphQL
6
6
  class Schema
7
7
  class Field
8
- include GraphQL::Schema::Member::CachedGraphQLDefinition
9
- include GraphQL::Schema::Member::AcceptsDefinition
10
8
  include GraphQL::Schema::Member::HasArguments
11
9
  include GraphQL::Schema::Member::HasAstNode
12
10
  include GraphQL::Schema::Member::HasPath
@@ -38,7 +36,9 @@ module GraphQL
38
36
 
39
37
  # @return [Class] The GraphQL type this field belongs to. (For fields defined on mutations, it's the payload type)
40
38
  def owner_type
41
- @owner_type ||= if owner < GraphQL::Schema::Mutation
39
+ @owner_type ||= if owner.nil?
40
+ raise GraphQL::InvariantError, "Field #{original_name.inspect} (graphql name: #{graphql_name.inspect}) has no owner, but all fields should have an owner. How did this happen?!"
41
+ elsif owner < GraphQL::Schema::Mutation
42
42
  owner.payload_type
43
43
  else
44
44
  owner
@@ -82,16 +82,6 @@ module GraphQL
82
82
  # @return [GraphQL::Schema:Field] an instance of `self
83
83
  # @see {.initialize} for other options
84
84
  def self.from_options(name = nil, type = nil, desc = nil, resolver: nil, mutation: nil, subscription: nil,**kwargs, &block)
85
- if kwargs[:field]
86
- if kwargs[:field].is_a?(GraphQL::Field) && kwargs[:field] == GraphQL::Types::Relay::NodeField.graphql_definition
87
- GraphQL::Deprecation.warn("Legacy-style `GraphQL::Relay::Node.field` is being added to a class-based type. See `GraphQL::Types::Relay::NodeField` for a replacement.")
88
- return GraphQL::Types::Relay::NodeField
89
- elsif kwargs[:field].is_a?(GraphQL::Field) && kwargs[:field] == GraphQL::Types::Relay::NodesField.graphql_definition
90
- GraphQL::Deprecation.warn("Legacy-style `GraphQL::Relay::Node.plural_field` is being added to a class-based type. See `GraphQL::Types::Relay::NodesField` for a replacement.")
91
- return GraphQL::Types::Relay::NodesField
92
- end
93
- end
94
-
95
85
  if (parent_config = resolver || mutation || subscription)
96
86
  # Get the parent config, merge in local overrides
97
87
  kwargs = parent_config.field_options.merge(kwargs)
@@ -104,9 +94,6 @@ module GraphQL
104
94
  end
105
95
 
106
96
  if !type.nil?
107
- if type.is_a?(GraphQL::Field)
108
- raise ArgumentError, "A GraphQL::Field was passed as the second argument, use the `field:` keyword for this instead."
109
- end
110
97
  if desc
111
98
  if kwargs[:description]
112
99
  raise ArgumentError, "Provide description as a positional argument or `description:` keyword, but not both (#{desc.inspect}, #{kwargs[:description].inspect})"
@@ -188,6 +175,7 @@ module GraphQL
188
175
  # @param deprecation_reason [String] If present, the field is marked "deprecated" with this message
189
176
  # @param method [Symbol] The method to call on the underlying object to resolve this field (defaults to `name`)
190
177
  # @param hash_key [String, Symbol] The hash key to lookup on the underlying object (if its a Hash) to resolve this field (defaults to `name` or `name.to_s`)
178
+ # @param dig [Array<String, Symbol>] The nested hash keys to lookup on the underlying hash to resolve this field using dig
191
179
  # @param resolver_method [Symbol] The method on the type to call to resolve this field (defaults to `name`)
192
180
  # @param connection [Boolean] `true` if this field should get automagic connection behavior; default is to infer by `*Connection` in the return type name
193
181
  # @param connection_extension [Class] The extension to add, to implement connections. If `nil`, no extension is added.
@@ -209,8 +197,7 @@ module GraphQL
209
197
  # @param ast_node [Language::Nodes::FieldDefinition, nil] If this schema was parsed from definition, this AST node defined the field
210
198
  # @param method_conflict_warning [Boolean] If false, skip the warning if this field's method conflicts with a built-in method
211
199
  # @param validates [Array<Hash>] Configurations for validating this field
212
- # @param legacy_edge_class [Class, nil] (DEPRECATED) If present, pass this along to the legacy field definition
213
- def initialize(type: nil, name: nil, owner: nil, null: true, field: nil, function: nil, description: nil, deprecation_reason: nil, method: nil, hash_key: nil, resolver_method: nil, resolve: nil, connection: nil, max_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: 1, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, legacy_edge_class: nil, &definition_block)
200
+ def initialize(type: nil, name: nil, owner: nil, null: true, field: nil, function: nil, description: nil, deprecation_reason: nil, method: nil, hash_key: nil, dig: nil, resolver_method: nil, resolve: nil, connection: nil, max_page_size: :not_given, scope: nil, introspection: false, camelize: true, trace: nil, complexity: 1, ast_node: nil, extras: EMPTY_ARRAY, extensions: EMPTY_ARRAY, connection_extension: self.class.connection_extension, resolver_class: nil, subscription_scope: nil, relay_node_field: false, relay_nodes_field: false, method_conflict_warning: true, broadcastable: nil, arguments: EMPTY_HASH, directives: EMPTY_HASH, validates: EMPTY_ARRAY, &definition_block)
214
201
  if name.nil?
215
202
  raise ArgumentError, "missing first `name` argument or keyword `name:`"
216
203
  end
@@ -236,8 +223,8 @@ module GraphQL
236
223
  @resolve = resolve
237
224
  self.deprecation_reason = deprecation_reason
238
225
 
239
- if method && hash_key
240
- raise ArgumentError, "Provide `method:` _or_ `hash_key:`, not both. (called with: `method: #{method.inspect}, hash_key: #{hash_key.inspect}`)"
226
+ if method && hash_key && dig
227
+ raise ArgumentError, "Provide `method:`, `hash_key:` _or_ `dig:`, not multiple. (called with: `method: #{method.inspect}, hash_key: #{hash_key.inspect}, dig: #{dig.inspect}`)"
241
228
  end
242
229
 
243
230
  if resolver_method
@@ -245,13 +232,14 @@ module GraphQL
245
232
  raise ArgumentError, "Provide `method:` _or_ `resolver_method:`, not both. (called with: `method: #{method.inspect}, resolver_method: #{resolver_method.inspect}`)"
246
233
  end
247
234
 
248
- if hash_key
249
- raise ArgumentError, "Provide `hash_key:` _or_ `resolver_method:`, not both. (called with: `hash_key: #{hash_key.inspect}, resolver_method: #{resolver_method.inspect}`)"
235
+ if hash_key || dig
236
+ raise ArgumentError, "Provide `hash_key:`, `dig:`, _or_ `resolver_method:`, not multiple. (called with: `hash_key: #{hash_key.inspect}, dig: #{dig.inspect}, resolver_method: #{resolver_method.inspect}`)"
250
237
  end
251
238
  end
252
239
 
253
240
  # TODO: I think non-string/symbol hash keys are wrongly normalized (eg `1` will not work)
254
241
  method_name = method || hash_key || name_s
242
+ @dig_keys = dig
255
243
  resolver_method ||= name_s.to_sym
256
244
 
257
245
  @method_str = -method_name.to_s
@@ -273,7 +261,6 @@ module GraphQL
273
261
  @relay_nodes_field = relay_nodes_field
274
262
  @ast_node = ast_node
275
263
  @method_conflict_warning = method_conflict_warning
276
- @legacy_edge_class = legacy_edge_class
277
264
 
278
265
  arguments.each do |name, arg|
279
266
  case arg
@@ -424,11 +411,14 @@ module GraphQL
424
411
  elsif connection?
425
412
  arguments = query.arguments_for(nodes.first, self)
426
413
  max_possible_page_size = nil
427
- if arguments[:first]
428
- max_possible_page_size = arguments[:first]
429
- end
430
- if arguments[:last] && (max_possible_page_size.nil? || arguments[:last] > max_possible_page_size)
431
- max_possible_page_size = arguments[:last]
414
+ if arguments.respond_to?(:[]) # It might have been an error
415
+ if arguments[:first]
416
+ max_possible_page_size = arguments[:first]
417
+ end
418
+
419
+ if arguments[:last] && (max_possible_page_size.nil? || arguments[:last] > max_possible_page_size)
420
+ max_possible_page_size = arguments[:last]
421
+ end
432
422
  end
433
423
 
434
424
  if max_possible_page_size.nil?
@@ -501,82 +491,6 @@ module GraphQL
501
491
  # @return [Integer, nil] Applied to connections if {#has_max_page_size?}
502
492
  attr_reader :max_page_size
503
493
 
504
- prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
505
-
506
- # @return [GraphQL::Field]
507
- def to_graphql
508
- field_defn = if @field
509
- @field.dup
510
- elsif @function
511
- GraphQL::Function.build_field(@function)
512
- else
513
- GraphQL::Field.new
514
- end
515
-
516
- field_defn.name = @name
517
- if @return_type_expr
518
- field_defn.type = -> { type }
519
- end
520
-
521
- if @description
522
- field_defn.description = @description
523
- end
524
-
525
- if self.deprecation_reason
526
- field_defn.deprecation_reason = self.deprecation_reason
527
- end
528
-
529
- if @resolver_class
530
- if @resolver_class < GraphQL::Schema::Mutation
531
- field_defn.mutation = @resolver_class
532
- end
533
- field_defn.metadata[:resolver] = @resolver_class
534
- end
535
-
536
- if !@trace.nil?
537
- field_defn.trace = @trace
538
- end
539
-
540
- if @relay_node_field
541
- field_defn.relay_node_field = @relay_node_field
542
- end
543
-
544
- if @relay_nodes_field
545
- field_defn.relay_nodes_field = @relay_nodes_field
546
- end
547
-
548
- if @legacy_edge_class
549
- field_defn.edge_class = @legacy_edge_class
550
- end
551
-
552
- field_defn.resolve = self.method(:resolve_field)
553
- field_defn.connection = connection?
554
- field_defn.connection_max_page_size = max_page_size
555
- field_defn.introspection = @introspection
556
- field_defn.complexity = @complexity
557
- field_defn.subscription_scope = @subscription_scope
558
- field_defn.ast_node = ast_node
559
-
560
- all_argument_definitions.each do |defn|
561
- arg_graphql = defn.deprecated_to_graphql
562
- field_defn.arguments[arg_graphql.name] = arg_graphql # rubocop:disable Development/ContextIsPassedCop -- legacy-related
563
- end
564
-
565
- # Support a passed-in proc, one way or another
566
- @resolve_proc = if @resolve
567
- @resolve
568
- elsif @function
569
- @function
570
- elsif @field
571
- @field.resolve_proc
572
- end
573
-
574
- # Ok, `self` isn't a class, but this is for consistency with the classes
575
- field_defn.metadata[:type_class] = self
576
- field_defn.arguments_class = GraphQL::Query::Arguments.construct_arguments_class(field_defn)
577
- field_defn
578
- end
579
-
580
494
  class MissingReturnTypeError < GraphQL::Error; end
581
495
  attr_writer :type
582
496
 
@@ -659,37 +573,6 @@ module GraphQL
659
573
  end
660
574
  end
661
575
 
662
- # Implement {GraphQL::Field}'s resolve API.
663
- #
664
- # Eventually, we might hook up field instances to execution in another way. TBD.
665
- # @see #resolve for how the interpreter hooks up to it
666
- def resolve_field(obj, args, ctx)
667
- ctx.schema.after_lazy(obj) do |after_obj|
668
- # First, apply auth ...
669
- query_ctx = ctx.query.context
670
- # Some legacy fields can have `nil` here, not exactly sure why.
671
- # @see https://github.com/rmosolgo/graphql-ruby/issues/1990 before removing
672
- inner_obj = after_obj && after_obj.object
673
- ctx.schema.after_lazy(to_ruby_args(after_obj, args, ctx)) do |ruby_args|
674
- if authorized?(inner_obj, ruby_args, query_ctx)
675
- # Then if it passed, resolve the field
676
- if @resolve_proc
677
- # Might be nil, still want to call the func in that case
678
- with_extensions(inner_obj, ruby_args, query_ctx) do |extended_obj, extended_args|
679
- # Pass the GraphQL args here for compatibility:
680
- @resolve_proc.call(extended_obj, args, ctx)
681
- end
682
- else
683
- public_send_field(after_obj, ruby_args, query_ctx)
684
- end
685
- else
686
- err = GraphQL::UnauthorizedFieldError.new(object: inner_obj, type: obj.class, context: ctx, field: self)
687
- query_ctx.schema.unauthorized_field(err)
688
- end
689
- end
690
- end
691
- end
692
-
693
576
  # This method is called by the interpreter for each field.
694
577
  # You can extend it in your base field classes.
695
578
  # @param object [GraphQL::Schema::Object] An instance of some type class, wrapping an application object
@@ -722,7 +605,7 @@ module GraphQL
722
605
  err
723
606
  end
724
607
 
725
- # @param ctx [GraphQL::Query::Context::FieldResolutionContext]
608
+ # @param ctx [GraphQL::Query::Context]
726
609
  def fetch_extra(extra_name, ctx)
727
610
  if extra_name != :path && extra_name != :ast_node && respond_to?(extra_name)
728
611
  self.public_send(extra_name)
@@ -735,63 +618,6 @@ module GraphQL
735
618
 
736
619
  private
737
620
 
738
- NO_ARGS = {}.freeze
739
-
740
- # Convert a GraphQL arguments instance into a Ruby-style hash.
741
- #
742
- # @param obj [GraphQL::Schema::Object] The object where this field is being resolved
743
- # @param graphql_args [GraphQL::Query::Arguments]
744
- # @param field_ctx [GraphQL::Query::Context::FieldResolutionContext]
745
- # @return [Hash<Symbol => Any>]
746
- def to_ruby_args(obj, graphql_args, field_ctx)
747
- if graphql_args.any? || @extras.any?
748
- # Splat the GraphQL::Arguments to Ruby keyword arguments
749
- ruby_kwargs = graphql_args.to_kwargs
750
- maybe_lazies = []
751
- # Apply any `prepare` methods. Not great code organization, can this go somewhere better?
752
- arguments(field_ctx).each do |name, arg_defn|
753
- ruby_kwargs_key = arg_defn.keyword
754
-
755
- if ruby_kwargs.key?(ruby_kwargs_key)
756
- loads = arg_defn.loads
757
- value = ruby_kwargs[ruby_kwargs_key]
758
- loaded_value = if loads && !arg_defn.from_resolver?
759
- if arg_defn.type.list?
760
- loaded_values = value.map { |val| load_application_object(arg_defn, loads, val, field_ctx.query.context) }
761
- field_ctx.schema.after_any_lazies(loaded_values) { |result| result }
762
- else
763
- load_application_object(arg_defn, loads, value, field_ctx.query.context)
764
- end
765
- elsif arg_defn.type.list? && value.is_a?(Array)
766
- field_ctx.schema.after_any_lazies(value, &:itself)
767
- else
768
- value
769
- end
770
-
771
- maybe_lazies << field_ctx.schema.after_lazy(loaded_value) do |loaded_value|
772
- prepared_value = if arg_defn.prepare
773
- arg_defn.prepare_value(obj, loaded_value)
774
- else
775
- loaded_value
776
- end
777
-
778
- ruby_kwargs[ruby_kwargs_key] = prepared_value
779
- end
780
- end
781
- end
782
-
783
- @extras.each do |extra_arg|
784
- ruby_kwargs[extra_arg] = fetch_extra(extra_arg, field_ctx)
785
- end
786
-
787
- field_ctx.schema.after_any_lazies(maybe_lazies) do
788
- ruby_kwargs
789
- end
790
- else
791
- NO_ARGS
792
- end
793
- end
794
-
795
621
  def public_send_field(unextended_obj, unextended_ruby_kwargs, query_ctx)
796
622
  with_extensions(unextended_obj, unextended_ruby_kwargs, query_ctx) do |obj, ruby_kwargs|
797
623
  begin
@@ -822,7 +648,9 @@ module GraphQL
822
648
  end
823
649
  elsif obj.object.is_a?(Hash)
824
650
  inner_object = obj.object
825
- if inner_object.key?(@method_sym)
651
+ if @dig_keys
652
+ inner_object.dig(*@dig_keys)
653
+ elsif inner_object.key?(@method_sym)
826
654
  inner_object[@method_sym]
827
655
  else
828
656
  inner_object[@method_str]
@@ -2,7 +2,6 @@
2
2
  module GraphQL
3
3
  class Schema
4
4
  class InputObject < GraphQL::Schema::Member
5
- extend GraphQL::Schema::Member::AcceptsDefinition
6
5
  extend Forwardable
7
6
  extend GraphQL::Schema::Member::HasArguments
8
7
  extend GraphQL::Schema::Member::HasArguments::ArgumentObjectLoader
@@ -13,49 +12,28 @@ module GraphQL
13
12
 
14
13
  # @return [GraphQL::Query::Context] The context for this query
15
14
  attr_reader :context
16
- # @return [GraphQL::Query::Arguments, GraphQL::Execution::Interpereter::Arguments] The underlying arguments instance
15
+ # @return [GraphQL::Execution::Interpereter::Arguments] The underlying arguments instance
17
16
  attr_reader :arguments
18
17
 
19
18
  # Ruby-like hash behaviors, read-only
20
19
  def_delegators :@ruby_style_hash, :keys, :values, :each, :map, :any?, :empty?
21
20
 
22
- def initialize(arguments = nil, ruby_kwargs: nil, context:, defaults_used:)
21
+ def initialize(arguments, ruby_kwargs:, context:, defaults_used:)
23
22
  @context = context
24
- if ruby_kwargs
25
- @ruby_style_hash = ruby_kwargs
26
- @arguments = arguments
27
- else
28
- @arguments = self.class.arguments_class.new(arguments, context: context, defaults_used: defaults_used)
29
- # Symbolized, underscored hash:
30
- @ruby_style_hash = @arguments.to_kwargs
31
- end
23
+ @ruby_style_hash = ruby_kwargs
24
+ @arguments = arguments
32
25
  # Apply prepares, not great to have it duplicated here.
33
- maybe_lazies = []
34
26
  self.class.arguments(context).each_value do |arg_defn|
35
27
  ruby_kwargs_key = arg_defn.keyword
36
-
37
28
  if @ruby_style_hash.key?(ruby_kwargs_key)
38
- loads = arg_defn.loads
39
- # Resolvers do this loading themselves;
40
- # With the interpreter, it's done during `coerce_arguments`
41
- if loads && !arg_defn.from_resolver? && !context.interpreter?
42
- value = @ruby_style_hash[ruby_kwargs_key]
43
- loaded_value = arg_defn.load_and_authorize_value(self, value, context)
44
- maybe_lazies << context.schema.after_lazy(loaded_value) do |loaded_value|
45
- overwrite_argument(ruby_kwargs_key, loaded_value)
46
- end
47
- end
48
-
49
29
  # Weirdly, procs are applied during coercion, but not methods.
50
30
  # Probably because these methods require a `self`.
51
- if arg_defn.prepare.is_a?(Symbol) || context.nil? || !context.interpreter?
31
+ if arg_defn.prepare.is_a?(Symbol) || context.nil?
52
32
  prepared_value = arg_defn.prepare_value(self, @ruby_style_hash[ruby_kwargs_key])
53
33
  overwrite_argument(ruby_kwargs_key, prepared_value)
54
34
  end
55
35
  end
56
36
  end
57
-
58
- @maybe_lazies = maybe_lazies
59
37
  end
60
38
 
61
39
  def to_h
@@ -68,12 +46,10 @@ module GraphQL
68
46
 
69
47
  def prepare
70
48
  if @context
71
- @context.schema.after_any_lazies(@maybe_lazies) do
72
- object = @context[:current_object]
73
- # Pass this object's class with `as` so that messages are rendered correctly from inherited validators
74
- Schema::Validator.validate!(self.class.validators, object, @context, @ruby_style_hash, as: self.class)
75
- self
76
- end
49
+ object = @context[:current_object]
50
+ # Pass this object's class with `as` so that messages are rendered correctly from inherited validators
51
+ Schema::Validator.validate!(self.class.validators, object, @context, @ruby_style_hash, as: self.class)
52
+ self
77
53
  else
78
54
  self
79
55
  end
@@ -81,9 +57,8 @@ module GraphQL
81
57
 
82
58
  def self.authorized?(obj, value, ctx)
83
59
  # Authorize each argument (but this doesn't apply if `prepare` is implemented):
84
- if value.is_a?(InputObject)
60
+ if value.respond_to?(:key?)
85
61
  arguments(ctx).each do |_name, input_obj_arg|
86
- input_obj_arg = input_obj_arg.type_class
87
62
  if value.key?(input_obj_arg.keyword) &&
88
63
  !input_obj_arg.authorized?(obj, value[input_obj_arg.keyword], ctx)
89
64
  return false
@@ -132,9 +107,6 @@ module GraphQL
132
107
  end
133
108
 
134
109
  class << self
135
- # @return [Class<GraphQL::Arguments>]
136
- attr_accessor :arguments_class
137
-
138
110
  def argument(*args, **kwargs, &block)
139
111
  argument_defn = super(*args, **kwargs, &block)
140
112
  # Add a method access
@@ -147,25 +119,6 @@ module GraphQL
147
119
  argument_defn
148
120
  end
149
121
 
150
- prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
151
-
152
- def to_graphql
153
- type_defn = GraphQL::InputObjectType.new
154
- type_defn.name = graphql_name
155
- type_defn.description = description
156
- type_defn.metadata[:type_class] = self
157
- type_defn.mutation = mutation
158
- type_defn.ast_node = ast_node
159
- all_argument_definitions.each do |arg|
160
- type_defn.arguments[arg.graphql_definition(silence_deprecation_warning: true).name] = arg.graphql_definition(silence_deprecation_warning: true) # rubocop:disable Development/ContextIsPassedCop -- legacy-related
161
- end
162
- # Make a reference to a classic-style Arguments class
163
- self.arguments_class = GraphQL::Query::Arguments.construct_arguments_class(type_defn)
164
- # But use this InputObject class at runtime
165
- type_defn.arguments_class = self
166
- type_defn
167
- end
168
-
169
122
  def kind
170
123
  GraphQL::TypeKinds::INPUT_OBJECT
171
124
  end
@@ -4,8 +4,6 @@ module GraphQL
4
4
  module Interface
5
5
  include GraphQL::Schema::Member::GraphQLTypeNames
6
6
  module DefinitionMethods
7
- include GraphQL::Schema::Member::CachedGraphQLDefinition
8
- include GraphQL::Relay::TypeExtensions
9
7
  include GraphQL::Schema::Member::BaseDSLMethods
10
8
  # ConfigurationExtension's responsibilities are in `def included` below
11
9
  include GraphQL::Schema::Member::TypeSystemHelpers
@@ -100,34 +98,11 @@ module GraphQL
100
98
  end
101
99
  end
102
100
 
103
- prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
104
-
105
- def to_graphql
106
- type_defn = GraphQL::InterfaceType.new
107
- type_defn.name = graphql_name
108
- type_defn.description = description
109
- type_defn.orphan_types = orphan_types
110
- type_defn.type_membership_class = self.type_membership_class
111
- type_defn.ast_node = ast_node
112
- fields.each do |field_name, field_inst| # rubocop:disable Development/ContextIsPassedCop -- legacy-related
113
- field_defn = field_inst.graphql_definition(silence_deprecation_warning: true)
114
- type_defn.fields[field_defn.name] = field_defn # rubocop:disable Development/ContextIsPassedCop -- legacy-related
115
- end
116
- type_defn.metadata[:type_class] = self
117
- if respond_to?(:resolve_type)
118
- type_defn.resolve_type = method(:resolve_type)
119
- end
120
- type_defn
121
- end
122
-
123
101
  def kind
124
102
  GraphQL::TypeKinds::INTERFACE
125
103
  end
126
104
  end
127
105
 
128
- # Extend this _after_ `DefinitionMethods` is defined, so it will be used
129
- extend GraphQL::Schema::Member::AcceptsDefinition
130
-
131
106
  extend DefinitionMethods
132
107
 
133
108
  def unwrap
@@ -89,9 +89,9 @@ module GraphQL
89
89
  case late_bound_type
90
90
  when GraphQL::Schema::LateBoundType
91
91
  @schema.get_type(late_bound_type.name)
92
- when GraphQL::Schema::List, GraphQL::ListType
92
+ when GraphQL::Schema::List
93
93
  resolve_late_binding(late_bound_type.of_type).to_list_type
94
- when GraphQL::Schema::NonNull, GraphQL::NonNullType
94
+ when GraphQL::Schema::NonNull
95
95
  resolve_late_binding(late_bound_type.of_type).to_non_null_type
96
96
  when Module
97
97
  # It's a normal type -- no change required
@@ -103,12 +103,7 @@ module GraphQL
103
103
 
104
104
  def load_constant(class_name)
105
105
  const = @custom_namespace.const_get(class_name)
106
- if @class_based
107
- dup_type_class(const)
108
- else
109
- # Use `.to_graphql` to get a freshly-made version, not shared between schemas
110
- const.deprecated_to_graphql
111
- end
106
+ dup_type_class(const)
112
107
  rescue NameError
113
108
  # Dup the built-in so that the cached fields aren't shared
114
109
  dup_type_class(@built_in_namespace.const_get(class_name))
@@ -16,11 +16,11 @@ module GraphQL
16
16
  end
17
17
 
18
18
  def to_non_null_type
19
- @to_non_null_type ||= GraphQL::NonNullType.new(of_type: self)
19
+ @to_non_null_type ||= GraphQL::Schema::NonNull.new(self)
20
20
  end
21
21
 
22
22
  def to_list_type
23
- @to_list_type ||= GraphQL::ListType.new(of_type: self)
23
+ @to_list_type ||= GraphQL::Schema::List.new(self)
24
24
  end
25
25
 
26
26
  def inspect
@@ -8,12 +8,6 @@ module GraphQL
8
8
  class List < GraphQL::Schema::Wrapper
9
9
  include Schema::Member::ValidatesInput
10
10
 
11
- prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
12
-
13
- def to_graphql
14
- @of_type.graphql_definition(silence_deprecation_warning: true).to_list_type
15
- end
16
-
17
11
  # @return [GraphQL::TypeKinds::LIST]
18
12
  def kind
19
13
  GraphQL::TypeKinds::LIST
@@ -202,7 +202,6 @@ module GraphQL
202
202
  description: arg["description"],
203
203
  deprecation_reason: arg["deprecationReason"],
204
204
  required: false,
205
- method_access: false,
206
205
  camelize: false,
207
206
  }
208
207
 
@@ -94,11 +94,6 @@ module GraphQL
94
94
  end
95
95
  end
96
96
 
97
- # @return [GraphQL::BaseType] Convert this type to a legacy-style object.
98
- def to_graphql
99
- raise GraphQL::RequiredImplementationMissingError
100
- end
101
-
102
97
  alias :unwrap :itself
103
98
 
104
99
  # Creates the default name for a schema member.
@@ -35,18 +35,16 @@ module GraphQL
35
35
  else
36
36
  maybe_type = constantize(type_expr)
37
37
  case maybe_type
38
- when GraphQL::BaseType
39
- maybe_type
40
38
  when Module
41
39
  # This is a way to check that it's the right kind of module:
42
- if maybe_type.respond_to?(:graphql_definition)
40
+ if maybe_type.respond_to?(:kind)
43
41
  maybe_type
44
42
  else
45
43
  raise ArgumentError, "Unexpected class/module found for GraphQL type: #{type_expr} (must be type definition class/module)"
46
44
  end
47
45
  end
48
46
  end
49
- when GraphQL::BaseType, GraphQL::Schema::LateBoundType
47
+ when GraphQL::Schema::LateBoundType
50
48
  type_expr
51
49
  when Array
52
50
  case type_expr.length
@@ -68,7 +66,7 @@ module GraphQL
68
66
  type_expr
69
67
  when Module
70
68
  # This is a way to check that it's the right kind of module:
71
- if type_expr.respond_to?(:graphql_definition)
69
+ if type_expr.respond_to?(:kind)
72
70
  type_expr
73
71
  else
74
72
  # Eg `String` => GraphQL::Types::String
@@ -100,7 +98,7 @@ module GraphQL
100
98
 
101
99
  def to_type_name(something)
102
100
  case something
103
- when GraphQL::BaseType, GraphQL::Schema::LateBoundType
101
+ when GraphQL::Schema::LateBoundType
104
102
  something.unwrap.name
105
103
  when Array
106
104
  to_type_name(something.first)
@@ -14,7 +14,7 @@ module GraphQL
14
14
  end
15
15
 
16
16
  # @see {GraphQL::Schema::Argument#initialize} for parameters
17
- # @return [GraphQL::Schema::Argument] An instance of {arguments_class}, created from `*args`
17
+ # @return [GraphQL::Schema::Argument] An instance of {argument_class}, created from `*args`
18
18
  def argument(*args, **kwargs, &block)
19
19
  kwargs[:owner] = self
20
20
  loads = kwargs[:loads]
@@ -291,26 +291,22 @@ module GraphQL
291
291
  # This object was loaded successfully
292
292
  # and resolved to the right type,
293
293
  # now apply the `.authorized?` class method if there is one
294
- if (class_based_type = application_object_type.type_class)
295
- context.schema.after_lazy(class_based_type.authorized?(application_object, context)) do |authed|
296
- if authed
297
- application_object
294
+ context.schema.after_lazy(application_object_type.authorized?(application_object, context)) do |authed|
295
+ if authed
296
+ application_object
297
+ else
298
+ err = GraphQL::UnauthorizedError.new(
299
+ object: application_object,
300
+ type: application_object_type,
301
+ context: context,
302
+ )
303
+ if self.respond_to?(:unauthorized_object)
304
+ err.set_backtrace(caller)
305
+ unauthorized_object(err)
298
306
  else
299
- err = GraphQL::UnauthorizedError.new(
300
- object: application_object,
301
- type: class_based_type,
302
- context: context,
303
- )
304
- if self.respond_to?(:unauthorized_object)
305
- err.set_backtrace(caller)
306
- unauthorized_object(err)
307
- else
308
- raise err
309
- end
307
+ raise err
310
308
  end
311
309
  end
312
- else
313
- application_object
314
310
  end
315
311
  end
316
312
  end
@@ -103,10 +103,10 @@ module GraphQL
103
103
  end
104
104
 
105
105
  def global_id_field(field_name, **kwargs)
106
- id_resolver = GraphQL::Relay::GlobalIdResolve.new(type: self)
106
+ type = self
107
107
  field field_name, "ID", **kwargs, null: false
108
108
  define_method(field_name) do
109
- id_resolver.call(object, {}, context)
109
+ context.schema.id_from_object(object, type, context)
110
110
  end
111
111
  end
112
112