graphql 1.13.14 → 2.0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/install_generator.rb +1 -1
  3. data/lib/generators/graphql/relay.rb +3 -17
  4. data/lib/generators/graphql/templates/schema.erb +3 -0
  5. data/lib/graphql/analysis/ast/field_usage.rb +3 -1
  6. data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
  7. data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
  8. data/lib/graphql/analysis/ast/query_depth.rb +0 -1
  9. data/lib/graphql/analysis/ast/visitor.rb +43 -36
  10. data/lib/graphql/analysis/ast.rb +2 -12
  11. data/lib/graphql/analysis.rb +0 -7
  12. data/lib/graphql/backtrace/table.rb +2 -20
  13. data/lib/graphql/backtrace/tracer.rb +2 -3
  14. data/lib/graphql/backtrace.rb +2 -8
  15. data/lib/graphql/dataloader/null_dataloader.rb +3 -1
  16. data/lib/graphql/dataloader/source.rb +9 -0
  17. data/lib/graphql/dataloader.rb +4 -1
  18. data/lib/graphql/dig.rb +1 -1
  19. data/lib/graphql/execution/errors.rb +12 -82
  20. data/lib/graphql/execution/interpreter/resolve.rb +26 -0
  21. data/lib/graphql/execution/interpreter/runtime.rb +163 -120
  22. data/lib/graphql/execution/interpreter.rb +187 -78
  23. data/lib/graphql/execution/lazy.rb +7 -21
  24. data/lib/graphql/execution/lookahead.rb +44 -40
  25. data/lib/graphql/execution/multiplex.rb +3 -174
  26. data/lib/graphql/execution.rb +11 -4
  27. data/lib/graphql/introspection/directive_type.rb +2 -2
  28. data/lib/graphql/introspection/dynamic_fields.rb +3 -8
  29. data/lib/graphql/introspection/entry_points.rb +2 -15
  30. data/lib/graphql/introspection/field_type.rb +1 -1
  31. data/lib/graphql/introspection/schema_type.rb +2 -2
  32. data/lib/graphql/introspection/type_type.rb +13 -6
  33. data/lib/graphql/introspection.rb +4 -3
  34. data/lib/graphql/language/document_from_schema_definition.rb +18 -35
  35. data/lib/graphql/language/lexer.rb +216 -1488
  36. data/lib/graphql/language/lexer.ri +744 -0
  37. data/lib/graphql/language/nodes.rb +41 -33
  38. data/lib/graphql/language/parser.rb +375 -363
  39. data/lib/graphql/language/parser.y +48 -43
  40. data/lib/graphql/language/printer.rb +37 -21
  41. data/lib/graphql/language/visitor.rb +191 -83
  42. data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
  43. data/lib/graphql/pagination/array_connection.rb +4 -2
  44. data/lib/graphql/pagination/connection.rb +31 -4
  45. data/lib/graphql/pagination/connections.rb +3 -28
  46. data/lib/graphql/pagination/relation_connection.rb +2 -0
  47. data/lib/graphql/query/context.rb +155 -196
  48. data/lib/graphql/query/input_validation_result.rb +10 -1
  49. data/lib/graphql/query/null_context.rb +0 -3
  50. data/lib/graphql/query/validation_pipeline.rb +12 -37
  51. data/lib/graphql/query/variable_validation_error.rb +2 -2
  52. data/lib/graphql/query/variables.rb +35 -21
  53. data/lib/graphql/query.rb +32 -43
  54. data/lib/graphql/railtie.rb +0 -104
  55. data/lib/graphql/rake_task/validate.rb +1 -1
  56. data/lib/graphql/rake_task.rb +29 -1
  57. data/lib/graphql/relay/range_add.rb +9 -20
  58. data/lib/graphql/relay.rb +0 -15
  59. data/lib/graphql/schema/addition.rb +7 -9
  60. data/lib/graphql/schema/argument.rb +36 -43
  61. data/lib/graphql/schema/build_from_definition.rb +32 -18
  62. data/lib/graphql/schema/directive/one_of.rb +12 -0
  63. data/lib/graphql/schema/directive/transform.rb +1 -1
  64. data/lib/graphql/schema/directive.rb +12 -23
  65. data/lib/graphql/schema/enum.rb +29 -41
  66. data/lib/graphql/schema/enum_value.rb +5 -25
  67. data/lib/graphql/schema/field/connection_extension.rb +4 -0
  68. data/lib/graphql/schema/field.rb +245 -343
  69. data/lib/graphql/schema/input_object.rb +57 -69
  70. data/lib/graphql/schema/interface.rb +0 -35
  71. data/lib/graphql/schema/introspection_system.rb +3 -8
  72. data/lib/graphql/schema/late_bound_type.rb +8 -2
  73. data/lib/graphql/schema/list.rb +18 -9
  74. data/lib/graphql/schema/loader.rb +1 -2
  75. data/lib/graphql/schema/member/base_dsl_methods.rb +15 -19
  76. data/lib/graphql/schema/member/build_type.rb +5 -7
  77. data/lib/graphql/schema/member/has_arguments.rb +146 -55
  78. data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
  79. data/lib/graphql/schema/member/has_directives.rb +71 -56
  80. data/lib/graphql/schema/member/has_fields.rb +16 -4
  81. data/lib/graphql/schema/member/has_interfaces.rb +49 -10
  82. data/lib/graphql/schema/member/has_validators.rb +31 -5
  83. data/lib/graphql/schema/member/relay_shortcuts.rb +28 -2
  84. data/lib/graphql/schema/member/type_system_helpers.rb +17 -0
  85. data/lib/graphql/schema/member/validates_input.rb +3 -3
  86. data/lib/graphql/schema/member.rb +0 -6
  87. data/lib/graphql/schema/mutation.rb +0 -9
  88. data/lib/graphql/schema/non_null.rb +3 -9
  89. data/lib/graphql/schema/object.rb +15 -52
  90. data/lib/graphql/schema/relay_classic_mutation.rb +53 -42
  91. data/lib/graphql/schema/resolver/has_payload_type.rb +20 -10
  92. data/lib/graphql/schema/resolver.rb +41 -42
  93. data/lib/graphql/schema/scalar.rb +8 -23
  94. data/lib/graphql/schema/subscription.rb +0 -7
  95. data/lib/graphql/schema/timeout.rb +24 -28
  96. data/lib/graphql/schema/type_membership.rb +3 -0
  97. data/lib/graphql/schema/union.rb +10 -17
  98. data/lib/graphql/schema/warden.rb +34 -8
  99. data/lib/graphql/schema/wrapper.rb +0 -5
  100. data/lib/graphql/schema.rb +240 -968
  101. data/lib/graphql/static_validation/all_rules.rb +1 -0
  102. data/lib/graphql/static_validation/base_visitor.rb +4 -21
  103. data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
  104. data/lib/graphql/static_validation/error.rb +2 -2
  105. data/lib/graphql/static_validation/literal_validator.rb +19 -1
  106. data/lib/graphql/static_validation/rules/directives_are_defined.rb +11 -5
  107. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
  108. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
  109. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
  110. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +12 -6
  111. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
  112. data/lib/graphql/static_validation/validator.rb +3 -25
  113. data/lib/graphql/static_validation.rb +0 -2
  114. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -1
  115. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
  116. data/lib/graphql/subscriptions/event.rb +3 -8
  117. data/lib/graphql/subscriptions/instrumentation.rb +0 -51
  118. data/lib/graphql/subscriptions.rb +32 -20
  119. data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
  120. data/lib/graphql/tracing/appoptics_trace.rb +231 -0
  121. data/lib/graphql/tracing/appsignal_trace.rb +66 -0
  122. data/lib/graphql/tracing/data_dog_trace.rb +148 -0
  123. data/lib/graphql/tracing/data_dog_tracing.rb +2 -0
  124. data/lib/graphql/tracing/new_relic_trace.rb +75 -0
  125. data/lib/graphql/tracing/notifications_trace.rb +41 -0
  126. data/lib/graphql/tracing/platform_trace.rb +107 -0
  127. data/lib/graphql/tracing/platform_tracing.rb +26 -40
  128. data/lib/graphql/tracing/prometheus_trace.rb +89 -0
  129. data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
  130. data/lib/graphql/tracing/scout_trace.rb +72 -0
  131. data/lib/graphql/tracing/statsd_trace.rb +56 -0
  132. data/lib/graphql/tracing.rb +136 -41
  133. data/lib/graphql/type_kinds.rb +6 -3
  134. data/lib/graphql/types/iso_8601_date.rb +4 -1
  135. data/lib/graphql/types/iso_8601_date_time.rb +4 -0
  136. data/lib/graphql/types/relay/base_connection.rb +16 -6
  137. data/lib/graphql/types/relay/connection_behaviors.rb +5 -25
  138. data/lib/graphql/types/relay/default_relay.rb +5 -9
  139. data/lib/graphql/types/relay/edge_behaviors.rb +1 -4
  140. data/lib/graphql/types/relay/node_behaviors.rb +5 -1
  141. data/lib/graphql/types/relay.rb +0 -2
  142. data/lib/graphql/types/string.rb +1 -1
  143. data/lib/graphql/version.rb +1 -1
  144. data/lib/graphql.rb +11 -72
  145. metadata +31 -133
  146. data/lib/graphql/analysis/analyze_query.rb +0 -98
  147. data/lib/graphql/analysis/field_usage.rb +0 -45
  148. data/lib/graphql/analysis/max_query_complexity.rb +0 -26
  149. data/lib/graphql/analysis/max_query_depth.rb +0 -26
  150. data/lib/graphql/analysis/query_complexity.rb +0 -88
  151. data/lib/graphql/analysis/query_depth.rb +0 -43
  152. data/lib/graphql/analysis/reducer_state.rb +0 -48
  153. data/lib/graphql/argument.rb +0 -131
  154. data/lib/graphql/authorization.rb +0 -82
  155. data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
  156. data/lib/graphql/backwards_compatibility.rb +0 -61
  157. data/lib/graphql/base_type.rb +0 -232
  158. data/lib/graphql/boolean_type.rb +0 -2
  159. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
  160. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
  161. data/lib/graphql/compatibility/execution_specification.rb +0 -436
  162. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
  163. data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
  164. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
  165. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
  166. data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
  167. data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
  168. data/lib/graphql/compatibility.rb +0 -5
  169. data/lib/graphql/define/assign_argument.rb +0 -12
  170. data/lib/graphql/define/assign_connection.rb +0 -13
  171. data/lib/graphql/define/assign_enum_value.rb +0 -18
  172. data/lib/graphql/define/assign_global_id_field.rb +0 -11
  173. data/lib/graphql/define/assign_mutation_function.rb +0 -34
  174. data/lib/graphql/define/assign_object_field.rb +0 -42
  175. data/lib/graphql/define/defined_object_proxy.rb +0 -53
  176. data/lib/graphql/define/instance_definable.rb +0 -255
  177. data/lib/graphql/define/no_definition_error.rb +0 -7
  178. data/lib/graphql/define/non_null_with_bang.rb +0 -16
  179. data/lib/graphql/define/type_definer.rb +0 -31
  180. data/lib/graphql/define.rb +0 -31
  181. data/lib/graphql/deprecated_dsl.rb +0 -55
  182. data/lib/graphql/directive/deprecated_directive.rb +0 -2
  183. data/lib/graphql/directive/include_directive.rb +0 -2
  184. data/lib/graphql/directive/skip_directive.rb +0 -2
  185. data/lib/graphql/directive.rb +0 -107
  186. data/lib/graphql/enum_type.rb +0 -133
  187. data/lib/graphql/execution/execute.rb +0 -333
  188. data/lib/graphql/execution/flatten.rb +0 -40
  189. data/lib/graphql/execution/instrumentation.rb +0 -92
  190. data/lib/graphql/execution/lazy/resolve.rb +0 -91
  191. data/lib/graphql/execution/typecast.rb +0 -50
  192. data/lib/graphql/field/resolve.rb +0 -59
  193. data/lib/graphql/field.rb +0 -226
  194. data/lib/graphql/float_type.rb +0 -2
  195. data/lib/graphql/function.rb +0 -128
  196. data/lib/graphql/id_type.rb +0 -2
  197. data/lib/graphql/input_object_type.rb +0 -138
  198. data/lib/graphql/int_type.rb +0 -2
  199. data/lib/graphql/interface_type.rb +0 -72
  200. data/lib/graphql/internal_representation/document.rb +0 -27
  201. data/lib/graphql/internal_representation/node.rb +0 -206
  202. data/lib/graphql/internal_representation/print.rb +0 -51
  203. data/lib/graphql/internal_representation/rewrite.rb +0 -184
  204. data/lib/graphql/internal_representation/scope.rb +0 -88
  205. data/lib/graphql/internal_representation/visit.rb +0 -36
  206. data/lib/graphql/internal_representation.rb +0 -7
  207. data/lib/graphql/language/lexer.rl +0 -260
  208. data/lib/graphql/list_type.rb +0 -80
  209. data/lib/graphql/non_null_type.rb +0 -71
  210. data/lib/graphql/object_type.rb +0 -130
  211. data/lib/graphql/query/arguments.rb +0 -189
  212. data/lib/graphql/query/arguments_cache.rb +0 -24
  213. data/lib/graphql/query/executor.rb +0 -52
  214. data/lib/graphql/query/literal_input.rb +0 -136
  215. data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
  216. data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
  217. data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
  218. data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
  219. data/lib/graphql/query/serial_execution.rb +0 -40
  220. data/lib/graphql/relay/array_connection.rb +0 -83
  221. data/lib/graphql/relay/base_connection.rb +0 -189
  222. data/lib/graphql/relay/connection_instrumentation.rb +0 -54
  223. data/lib/graphql/relay/connection_resolve.rb +0 -43
  224. data/lib/graphql/relay/connection_type.rb +0 -54
  225. data/lib/graphql/relay/edge.rb +0 -27
  226. data/lib/graphql/relay/edge_type.rb +0 -19
  227. data/lib/graphql/relay/edges_instrumentation.rb +0 -39
  228. data/lib/graphql/relay/global_id_resolve.rb +0 -17
  229. data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
  230. data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
  231. data/lib/graphql/relay/mutation/resolve.rb +0 -56
  232. data/lib/graphql/relay/mutation/result.rb +0 -38
  233. data/lib/graphql/relay/mutation.rb +0 -106
  234. data/lib/graphql/relay/node.rb +0 -39
  235. data/lib/graphql/relay/page_info.rb +0 -7
  236. data/lib/graphql/relay/relation_connection.rb +0 -188
  237. data/lib/graphql/relay/type_extensions.rb +0 -32
  238. data/lib/graphql/scalar_type.rb +0 -91
  239. data/lib/graphql/schema/catchall_middleware.rb +0 -35
  240. data/lib/graphql/schema/default_parse_error.rb +0 -10
  241. data/lib/graphql/schema/default_type_error.rb +0 -17
  242. data/lib/graphql/schema/member/accepts_definition.rb +0 -164
  243. data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
  244. data/lib/graphql/schema/member/instrumentation.rb +0 -131
  245. data/lib/graphql/schema/middleware_chain.rb +0 -82
  246. data/lib/graphql/schema/possible_types.rb +0 -44
  247. data/lib/graphql/schema/rescue_middleware.rb +0 -60
  248. data/lib/graphql/schema/timeout_middleware.rb +0 -88
  249. data/lib/graphql/schema/traversal.rb +0 -228
  250. data/lib/graphql/schema/validation.rb +0 -313
  251. data/lib/graphql/static_validation/default_visitor.rb +0 -15
  252. data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
  253. data/lib/graphql/string_type.rb +0 -2
  254. data/lib/graphql/subscriptions/subscription_root.rb +0 -76
  255. data/lib/graphql/tracing/opentelemetry_tracing.rb +0 -101
  256. data/lib/graphql/tracing/skylight_tracing.rb +0 -70
  257. data/lib/graphql/types/relay/node_field.rb +0 -24
  258. data/lib/graphql/types/relay/nodes_field.rb +0 -43
  259. data/lib/graphql/union_type.rb +0 -115
  260. data/lib/graphql/upgrader/member.rb +0 -937
  261. data/lib/graphql/upgrader/schema.rb +0 -38
@@ -8,7 +8,15 @@ module GraphQL
8
8
  if new_edge_type_class
9
9
  @edge_type_class = new_edge_type_class
10
10
  else
11
- @edge_type_class || find_inherited_value(:edge_type_class, Types::Relay::BaseEdge)
11
+ # Don't call `ancestor.edge_type_class`
12
+ # because we don't want a fallback from any ancestors --
13
+ # only apply the fallback if _no_ ancestor has a configured value!
14
+ for ancestor in self.ancestors
15
+ if ancestor.respond_to?(:configured_edge_type_class, true) && (etc = ancestor.configured_edge_type_class)
16
+ return etc
17
+ end
18
+ end
19
+ Types::Relay::BaseEdge
12
20
  end
13
21
  end
14
22
 
@@ -16,7 +24,15 @@ module GraphQL
16
24
  if new_connection_type_class
17
25
  @connection_type_class = new_connection_type_class
18
26
  else
19
- @connection_type_class || find_inherited_value(:connection_type_class, Types::Relay::BaseConnection)
27
+ # Don't call `ancestor.connection_type_class`
28
+ # because we don't want a fallback from any ancestors --
29
+ # only apply the fallback if _no_ ancestor has a configured value!
30
+ for ancestor in self.ancestors
31
+ if ancestor.respond_to?(:configured_connection_type_class, true) && (ctc = ancestor.configured_connection_type_class)
32
+ return ctc
33
+ end
34
+ end
35
+ Types::Relay::BaseConnection
20
36
  end
21
37
  end
22
38
 
@@ -41,6 +57,16 @@ module GraphQL
41
57
  end
42
58
  end
43
59
  end
60
+
61
+ protected
62
+
63
+ def configured_connection_type_class
64
+ @connection_type_class
65
+ end
66
+
67
+ def configured_edge_type_class
68
+ @edge_type_class
69
+ end
44
70
  end
45
71
  end
46
72
  end
@@ -4,6 +4,13 @@ module GraphQL
4
4
  class Schema
5
5
  class Member
6
6
  module TypeSystemHelpers
7
+ def initialize(*args, &block)
8
+ super
9
+ @to_non_null_type ||= nil
10
+ @to_list_type ||= nil
11
+ end
12
+ ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)
13
+
7
14
  # @return [Schema::NonNull] Make a non-null-type representation of this type
8
15
  def to_non_null_type
9
16
  @to_non_null_type ||= GraphQL::Schema::NonNull.new(self)
@@ -32,6 +39,16 @@ module GraphQL
32
39
  def kind
33
40
  raise GraphQL::RequiredImplementationMissingError, "No `.kind` defined for #{self}"
34
41
  end
42
+
43
+ private
44
+
45
+ def inherited(subclass)
46
+ super
47
+ subclass.class_eval do
48
+ @to_non_null_type ||= nil
49
+ @to_list_type ||= nil
50
+ end
51
+ end
35
52
  end
36
53
  end
37
54
  end
@@ -8,11 +8,11 @@ module GraphQL
8
8
  validate_input(val, ctx).valid?
9
9
  end
10
10
 
11
- def validate_input(val, ctx)
11
+ def validate_input(val, ctx, max_errors: nil)
12
12
  if val.nil?
13
- GraphQL::Query::InputValidationResult.new
13
+ Query::InputValidationResult::VALID
14
14
  else
15
- validate_non_null_input(val, ctx)
15
+ validate_non_null_input(val, ctx, max_errors: max_errors) || Query::InputValidationResult::VALID
16
16
  end
17
17
  end
18
18
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'graphql/schema/member/accepts_definition'
3
2
  require 'graphql/schema/member/base_dsl_methods'
4
- require 'graphql/schema/member/cached_graphql_definition'
5
3
  require 'graphql/schema/member/graphql_type_names'
6
4
  require 'graphql/schema/member/has_ast_node'
7
5
  require 'graphql/schema/member/has_directives'
@@ -14,7 +12,6 @@ require 'graphql/schema/member/relay_shortcuts'
14
12
  require 'graphql/schema/member/scoped'
15
13
  require 'graphql/schema/member/type_system_helpers'
16
14
  require 'graphql/schema/member/validates_input'
17
- require "graphql/relay/type_extensions"
18
15
 
19
16
  module GraphQL
20
17
  class Schema
@@ -24,8 +21,6 @@ module GraphQL
24
21
  # @api private
25
22
  class Member
26
23
  include GraphQLTypeNames
27
- extend CachedGraphQLDefinition
28
- extend GraphQL::Relay::TypeExtensions
29
24
  extend BaseDSLMethods
30
25
  extend BaseDSLMethods::ConfigurationExtension
31
26
  introspection(false)
@@ -41,5 +36,4 @@ end
41
36
 
42
37
  require 'graphql/schema/member/has_arguments'
43
38
  require 'graphql/schema/member/has_fields'
44
- require 'graphql/schema/member/instrumentation'
45
39
  require 'graphql/schema/member/build_type'
@@ -63,15 +63,6 @@ module GraphQL
63
63
  extend GraphQL::Schema::Resolver::HasPayloadType
64
64
 
65
65
  class << self
66
- # Override this method to handle legacy-style usages of `MyMutation.field`
67
- def field(*args, **kwargs, &block)
68
- if args.empty?
69
- raise ArgumentError, "#{name}.field is used for adding fields to this mutation. Use `mutation: #{name}` to attach this mutation instead."
70
- else
71
- super
72
- end
73
- end
74
-
75
66
  def visible?(context)
76
67
  true
77
68
  end
@@ -8,13 +8,7 @@ module GraphQL
8
8
  class NonNull < 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_non_null_type
15
- end
16
-
17
- # @return [GraphQL::TypeKinds::NON_NULL]
11
+ # @return [GraphQL::TypeKinds::NON_NULL]
18
12
  def kind
19
13
  GraphQL::TypeKinds::NON_NULL
20
14
  end
@@ -37,13 +31,13 @@ module GraphQL
37
31
  "#<#{self.class.name} @of_type=#{@of_type.inspect}>"
38
32
  end
39
33
 
40
- def validate_input(value, ctx)
34
+ def validate_input(value, ctx, max_errors: nil)
41
35
  if value.nil?
42
36
  result = GraphQL::Query::InputValidationResult.new
43
37
  result.add_problem("Expected value to not be null")
44
38
  result
45
39
  else
46
- of_type.validate_input(value, ctx)
40
+ of_type.validate_input(value, ctx, max_errors: max_errors)
47
41
  end
48
42
  end
49
43
 
@@ -5,7 +5,6 @@ require "graphql/query/null_context"
5
5
  module GraphQL
6
6
  class Schema
7
7
  class Object < GraphQL::Schema::Member
8
- extend GraphQL::Schema::Member::AcceptsDefinition
9
8
  extend GraphQL::Schema::Member::HasFields
10
9
  extend GraphQL::Schema::Member::HasInterfaces
11
10
 
@@ -49,21 +48,19 @@ module GraphQL
49
48
  # @return [GraphQL::Schema::Object, GraphQL::Execution::Lazy]
50
49
  # @raise [GraphQL::UnauthorizedError] if the user-provided hook returns `false`
51
50
  def authorized_new(object, context)
52
- trace_payload = { context: context, type: self, object: object, path: context[:current_path] }
53
-
54
- maybe_lazy_auth_val = context.query.trace("authorized", trace_payload) do
55
- context.query.with_error_handling do
56
- begin
57
- authorized?(object, context)
58
- rescue GraphQL::UnauthorizedError => err
59
- context.schema.unauthorized_object(err)
60
- end
51
+ maybe_lazy_auth_val = context.query.current_trace.authorized(query: context.query, type: self, object: object) do
52
+ begin
53
+ authorized?(object, context)
54
+ rescue GraphQL::UnauthorizedError => err
55
+ context.schema.unauthorized_object(err)
56
+ rescue StandardError => err
57
+ context.query.handle_or_reraise(err)
61
58
  end
62
59
  end
63
60
 
64
61
  auth_val = if context.schema.lazy?(maybe_lazy_auth_val)
65
62
  GraphQL::Execution::Lazy.new do
66
- context.query.trace("authorized_lazy", trace_payload) do
63
+ context.query.current_trace.authorized_lazy(query: context.query, type: self, object: object) do
67
64
  context.schema.sync_lazy(maybe_lazy_auth_val)
68
65
  end
69
66
  end
@@ -99,48 +96,14 @@ module GraphQL
99
96
  class << self
100
97
  # Set up a type-specific invalid null error to use when this object's non-null fields wrongly return `nil`.
101
98
  # It should help with debugging and bug tracker integrations.
102
- def inherited(child_class)
103
- child_class.const_set(:InvalidNullError, GraphQL::InvalidNullError.subclass_for(child_class))
104
- super
105
- end
106
-
107
- # @return [Hash<String => GraphQL::Schema::Field>] All of this object's fields, indexed by name
108
- # @see get_field A faster way to find one field by name ({#fields} merges hashes of inherited fields; {#get_field} just looks up one field.)
109
- def fields(context = GraphQL::Query::NullContext)
110
- all_fields = super
111
- # This adds fields from legacy-style interfaces only.
112
- # Multi-fields are not supported here.
113
- interfaces.each do |int|
114
- if int.is_a?(GraphQL::InterfaceType)
115
- int_f = {}
116
- int.fields.each do |name, legacy_field| # rubocop:disable Development/ContextIsPassedCop -- legacy-related
117
- int_f[name] = field_class.from_options(name, field: legacy_field)
118
- end
119
- all_fields = int_f.merge(all_fields)
120
- end
121
- end
122
- all_fields
123
- end
124
-
125
- prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
126
-
127
- # @return [GraphQL::ObjectType]
128
- def to_graphql
129
- obj_type = GraphQL::ObjectType.new
130
- obj_type.name = graphql_name
131
- obj_type.description = description
132
- obj_type.structural_interface_type_memberships = interface_type_memberships
133
- obj_type.introspection = introspection
134
- obj_type.mutation = mutation
135
- obj_type.ast_node = ast_node
136
- fields.each do |field_name, field_inst| # rubocop:disable Development/ContextIsPassedCop -- legacy-related
137
- field_defn = field_inst.to_graphql(silence_deprecation_warning: true)
138
- obj_type.fields[field_defn.name] = field_defn # rubocop:disable Development/ContextIsPassedCop -- legacy-related
99
+ def const_missing(name)
100
+ if name == :InvalidNullError
101
+ custom_err_class = GraphQL::InvalidNullError.subclass_for(self)
102
+ const_set(:InvalidNullError, custom_err_class)
103
+ custom_err_class
104
+ else
105
+ super
139
106
  end
140
-
141
- obj_type.metadata[:type_class] = self
142
-
143
- obj_type
144
107
  end
145
108
 
146
109
  def kind
@@ -29,25 +29,19 @@ module GraphQL
29
29
  # Override {GraphQL::Schema::Resolver#resolve_with_support} to
30
30
  # delete `client_mutation_id` from the kwargs.
31
31
  def resolve_with_support(**inputs)
32
- # Without the interpreter, the inputs are unwrapped by an instrumenter.
33
- # But when using the interpreter, no instrumenters are applied.
34
- if context.interpreter?
35
- input = inputs[:input].to_kwargs
36
-
37
- new_extras = field ? field.extras : []
38
- all_extras = self.class.extras + new_extras
39
-
40
- # Transfer these from the top-level hash to the
41
- # shortcutted `input:` object
42
- all_extras.each do |ext|
43
- # It's possible that the `extra` was not passed along by this point,
44
- # don't re-add it if it wasn't given here.
45
- if inputs.key?(ext)
46
- input[ext] = inputs[ext]
47
- end
32
+ input = inputs[:input].to_kwargs
33
+
34
+ new_extras = field ? field.extras : []
35
+ all_extras = self.class.extras + new_extras
36
+
37
+ # Transfer these from the top-level hash to the
38
+ # shortcutted `input:` object
39
+ all_extras.each do |ext|
40
+ # It's possible that the `extra` was not passed along by this point,
41
+ # don't re-add it if it wasn't given here.
42
+ if inputs.key?(ext)
43
+ input[ext] = inputs[ext]
48
44
  end
49
- else
50
- input = inputs
51
45
  end
52
46
 
53
47
  if input
@@ -66,26 +60,46 @@ module GraphQL
66
60
  super()
67
61
  end
68
62
 
69
- # Again, this is done by an instrumenter when using non-interpreter execution.
70
- if context.interpreter?
71
- context.schema.after_lazy(return_value) do |return_hash|
72
- # It might be an error
73
- if return_hash.is_a?(Hash)
74
- return_hash[:client_mutation_id] = client_mutation_id
75
- end
76
- return_hash
63
+ context.schema.after_lazy(return_value) do |return_hash|
64
+ # It might be an error
65
+ if return_hash.is_a?(Hash)
66
+ return_hash[:client_mutation_id] = client_mutation_id
77
67
  end
78
- else
79
- return_value
68
+ return_hash
80
69
  end
81
70
  end
82
71
 
83
72
  class << self
73
+ def dummy
74
+ @dummy ||= begin
75
+ d = Class.new(GraphQL::Schema::Resolver)
76
+ d.argument_class(self.argument_class)
77
+ # TODO make this lazier?
78
+ d.argument(:input, input_type, description: "Parameters for #{self.graphql_name}")
79
+ d
80
+ end
81
+ end
82
+
83
+ def field_arguments(context = GraphQL::Query::NullContext)
84
+ dummy.arguments(context)
85
+ end
86
+
87
+ def get_field_argument(name, context = GraphQL::Query::NullContext)
88
+ dummy.get_argument(name, context)
89
+ end
90
+
91
+ def own_field_arguments
92
+ dummy.own_arguments
93
+ end
94
+
95
+ def all_field_argument_definitions
96
+ dummy.all_argument_definitions
97
+ end
84
98
 
85
99
  # Also apply this argument to the input type:
86
- def argument(*args, **kwargs, &block)
100
+ def argument(*args, own_argument: false, **kwargs, &block)
87
101
  it = input_type # make sure any inherited arguments are already added to it
88
- arg = super
102
+ arg = super(*args, **kwargs, &block)
89
103
 
90
104
  # This definition might be overriding something inherited;
91
105
  # if it is, remove the inherited definition so it's not confused at runtime as having multiple definitions
@@ -125,15 +139,6 @@ module GraphQL
125
139
  @input_type ||= generate_input_type
126
140
  end
127
141
 
128
- # Extend {Schema::Mutation.field_options} to add the `input` argument
129
- def field_options
130
- sig = super
131
- # Arguments were added at the root, but they should be nested
132
- sig[:arguments].clear
133
- sig[:arguments][:input] = { type: input_type, required: true, description: "Parameters for #{graphql_name}" }
134
- sig
135
- end
136
-
137
142
  private
138
143
 
139
144
  # Generate the input type for the `input:` argument
@@ -141,11 +146,17 @@ module GraphQL
141
146
  # @return [Class] a subclass of {.input_object_class}
142
147
  def generate_input_type
143
148
  mutation_args = all_argument_definitions
144
- mutation_name = graphql_name
145
149
  mutation_class = self
146
150
  Class.new(input_object_class) do
147
- graphql_name("#{mutation_name}Input")
148
- description("Autogenerated input type of #{mutation_name}")
151
+ class << self
152
+ def default_graphql_name
153
+ "#{self.mutation.graphql_name}Input"
154
+ end
155
+
156
+ def description(new_desc = nil)
157
+ super || "Autogenerated input type of #{self.mutation.graphql_name}"
158
+ end
159
+ end
149
160
  mutation(mutation_class)
150
161
  # these might be inherited:
151
162
  mutation_args.each do |arg|
@@ -20,7 +20,17 @@ module GraphQL
20
20
  @payload_type ||= generate_payload_type
21
21
  end
22
22
 
23
- alias :type :payload_type
23
+ def type(new_type = nil, null: nil)
24
+ if new_type
25
+ payload_type(new_type)
26
+ if !null.nil?
27
+ self.null(null)
28
+ end
29
+ else
30
+ super()
31
+ end
32
+ end
33
+
24
34
  alias :type_expr :payload_type
25
35
 
26
36
  def field_class(new_class = nil)
@@ -79,16 +89,16 @@ module GraphQL
79
89
  def generate_payload_type
80
90
  resolver_name = graphql_name
81
91
  resolver_fields = all_field_definitions
82
- Class.new(object_class) do
83
- graphql_name("#{resolver_name}Payload")
84
- description("Autogenerated return type of #{resolver_name}")
85
- resolver_fields.each do |f|
86
- # Reattach the already-defined field here
87
- # (The field's `.owner` will still point to the mutation, not the object type, I think)
88
- # Don't re-warn about a method conflict. Since this type is generated, it should be fixed in the resolver instead.
89
- add_field(f, method_conflict_warning: false)
90
- end
92
+ pt = Class.new(object_class)
93
+ pt.graphql_name("#{resolver_name}Payload")
94
+ pt.description("Autogenerated return type of #{resolver_name}.")
95
+ resolver_fields.each do |f|
96
+ # Reattach the already-defined field here
97
+ # (The field's `.owner` will still point to the mutation, not the object type, I think)
98
+ # Don't re-warn about a method conflict. Since this type is generated, it should be fixed in the resolver instead.
99
+ pt.add_field(f, method_conflict_warning: false)
91
100
  end
101
+ pt
92
102
  end
93
103
  end
94
104
  end
@@ -15,8 +15,6 @@ module GraphQL
15
15
  #
16
16
  # A resolver's configuration may be overridden with other keywords in the `field(...)` call.
17
17
  #
18
- # See the {.field_options} to see how a Resolver becomes a set of field configuration options.
19
- #
20
18
  # @see {GraphQL::Schema::Mutation} for a concrete subclass of `Resolver`.
21
19
  # @see {GraphQL::Function} `Resolver` is a replacement for `GraphQL::Function`
22
20
  class Resolver
@@ -75,7 +73,7 @@ module GraphQL
75
73
  context.schema.after_lazy(ready_val) do |is_ready, ready_early_return|
76
74
  if ready_early_return
77
75
  if is_ready != false
78
- raise "Unexpected result from #ready? (expected `true`, `false` or `[false, {...}]`): [#{authorized_result.inspect}, #{ready_early_return.inspect}]"
76
+ raise "Unexpected result from #ready? (expected `true`, `false` or `[false, {...}]`): [#{is_ready.inspect}, #{ready_early_return.inspect}]"
79
77
  else
80
78
  ready_early_return
81
79
  end
@@ -210,6 +208,18 @@ module GraphQL
210
208
  end
211
209
 
212
210
  class << self
211
+ def field_arguments(context = GraphQL::Query::NullContext)
212
+ arguments(context)
213
+ end
214
+
215
+ def get_field_argument(name, context = GraphQL::Query::NullContext)
216
+ get_argument(name, context)
217
+ end
218
+
219
+ def all_field_argument_definitions
220
+ all_argument_definitions
221
+ end
222
+
213
223
  # Default `:resolve` set below.
214
224
  # @return [Symbol] The method to call on instances of this object to resolve the field
215
225
  def resolve_method(new_method = nil)
@@ -242,6 +252,14 @@ module GraphQL
242
252
  @null.nil? ? (superclass.respond_to?(:null) ? superclass.null : true) : @null
243
253
  end
244
254
 
255
+ def resolver_method(new_method_name = nil)
256
+ if new_method_name
257
+ @resolver_method = new_method_name
258
+ else
259
+ @resolver_method || :resolve_with_support
260
+ end
261
+ end
262
+
245
263
  # Call this method to get the return type of the field,
246
264
  # or use it as a configuration method to assign a return type
247
265
  # instead of generating one.
@@ -257,8 +275,8 @@ module GraphQL
257
275
  @type_expr = new_type
258
276
  @null = null
259
277
  else
260
- if @type_expr
261
- GraphQL::Schema::Member::BuildType.parse_type(@type_expr, null: @null)
278
+ if type_expr
279
+ GraphQL::Schema::Member::BuildType.parse_type(type_expr, null: self.null)
262
280
  elsif superclass.respond_to?(:type)
263
281
  superclass.type
264
282
  else
@@ -307,47 +325,28 @@ module GraphQL
307
325
 
308
326
  # @return [Boolean] `true` if this resolver or a superclass has an assigned `max_page_size`
309
327
  def has_max_page_size?
310
- defined?(@max_page_size) || (superclass.respond_to?(:has_max_page_size?) && superclass.has_max_page_size?)
328
+ (!!defined?(@max_page_size)) || (superclass.respond_to?(:has_max_page_size?) && superclass.has_max_page_size?)
311
329
  end
312
330
 
313
- def field_options
314
-
315
- all_args = {}
316
- all_argument_definitions.each do |arg|
317
- if (prev_entry = all_args[arg.graphql_name])
318
- if prev_entry.is_a?(Array)
319
- prev_entry << arg
320
- else
321
- all_args[arg.graphql_name] = [prev_entry, arg]
322
- end
323
- else
324
- all_args[arg.graphql_name] = arg
325
- end
326
- end
327
-
328
- field_opts = {
329
- type: type_expr,
330
- description: description,
331
- extras: extras,
332
- resolver_method: :resolve_with_support,
333
- resolver_class: self,
334
- arguments: all_args,
335
- null: null,
336
- complexity: complexity,
337
- broadcastable: broadcastable?,
338
- }
339
-
340
- # If there aren't any, then the returned array is `[].freeze`,
341
- # but passing that along breaks some user code.
342
- if (exts = extensions).any?
343
- field_opts[:extensions] = exts
344
- end
345
-
346
- if has_max_page_size?
347
- field_opts[:max_page_size] = max_page_size
331
+ # Get or set the `default_page_size:` which will be configured for fields using this resolver
332
+ # (`nil` means "unlimited default page size".)
333
+ # @param default_page_size [Integer, nil] Set a new value
334
+ # @return [Integer, nil] The `default_page_size` assigned to fields that use this resolver
335
+ def default_page_size(new_default_page_size = :not_given)
336
+ if new_default_page_size != :not_given
337
+ @default_page_size = new_default_page_size
338
+ elsif defined?(@default_page_size)
339
+ @default_page_size
340
+ elsif superclass.respond_to?(:default_page_size)
341
+ superclass.default_page_size
342
+ else
343
+ nil
348
344
  end
345
+ end
349
346
 
350
- field_opts
347
+ # @return [Boolean] `true` if this resolver or a superclass has an assigned `default_page_size`
348
+ def has_default_page_size?
349
+ (!!defined?(@default_page_size)) || (superclass.respond_to?(:has_default_page_size?) && superclass.has_default_page_size?)
351
350
  end
352
351
 
353
352
  # A non-normalized type configuration, without `null` applied
@@ -2,7 +2,6 @@
2
2
  module GraphQL
3
3
  class Schema
4
4
  class Scalar < GraphQL::Schema::Member
5
- extend GraphQL::Schema::Member::AcceptsDefinition
6
5
  extend GraphQL::Schema::Member::ValidatesInput
7
6
 
8
7
  class << self
@@ -14,20 +13,6 @@ module GraphQL
14
13
  val
15
14
  end
16
15
 
17
- prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
18
-
19
- def to_graphql
20
- type_defn = GraphQL::ScalarType.new
21
- type_defn.name = graphql_name
22
- type_defn.description = description
23
- type_defn.coerce_result = method(:coerce_result)
24
- type_defn.coerce_input = method(:coerce_input)
25
- type_defn.metadata[:type_class] = self
26
- type_defn.default_scalar = default_scalar
27
- type_defn.ast_node = ast_node
28
- type_defn
29
- end
30
-
31
16
  def kind
32
17
  GraphQL::TypeKinds::SCALAR
33
18
  end
@@ -55,14 +40,13 @@ module GraphQL
55
40
  @default_scalar ||= false
56
41
  end
57
42
 
58
- def validate_non_null_input(value, ctx)
59
- result = Query::InputValidationResult.new
43
+ def validate_non_null_input(value, ctx, max_errors: nil)
60
44
  coerced_result = begin
61
- ctx.query.with_error_handling do
62
- coerce_input(value, ctx)
63
- end
45
+ coerce_input(value, ctx)
64
46
  rescue GraphQL::CoercionError => err
65
47
  err
48
+ rescue StandardError => err
49
+ ctx.query.handle_or_reraise(err)
66
50
  end
67
51
 
68
52
  if coerced_result.nil?
@@ -71,11 +55,12 @@ module GraphQL
71
55
  else
72
56
  " #{GraphQL::Language.serialize(value)}"
73
57
  end
74
- result.add_problem("Could not coerce value#{str_value} to #{graphql_name}")
58
+ Query::InputValidationResult.from_problem("Could not coerce value#{str_value} to #{graphql_name}")
75
59
  elsif coerced_result.is_a?(GraphQL::CoercionError)
76
- result.add_problem(coerced_result.message, message: coerced_result.message, extensions: coerced_result.extensions)
60
+ Query::InputValidationResult.from_problem(coerced_result.message, message: coerced_result.message, extensions: coerced_result.extensions)
61
+ else
62
+ nil
77
63
  end
78
- result
79
64
  end
80
65
  end
81
66
  end
@@ -143,13 +143,6 @@ module GraphQL
143
143
  def self.topic_for(arguments:, field:, scope:)
144
144
  Subscriptions::Serialize.dump_recursive([scope, field.graphql_name, arguments])
145
145
  end
146
-
147
- # Overriding Resolver#field_options to include subscription_scope
148
- def self.field_options
149
- super.merge(
150
- subscription_scope: subscription_scope
151
- )
152
- end
153
146
  end
154
147
  end
155
148
  end