graphql 1.13.12 → 2.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (273) 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/trace.rb +96 -0
  14. data/lib/graphql/backtrace/tracer.rb +2 -3
  15. data/lib/graphql/backtrace.rb +7 -8
  16. data/lib/graphql/dataloader/null_dataloader.rb +3 -1
  17. data/lib/graphql/dataloader/source.rb +9 -0
  18. data/lib/graphql/dataloader.rb +4 -1
  19. data/lib/graphql/dig.rb +1 -1
  20. data/lib/graphql/execution/errors.rb +12 -82
  21. data/lib/graphql/execution/interpreter/arguments.rb +1 -1
  22. data/lib/graphql/execution/interpreter/arguments_cache.rb +2 -3
  23. data/lib/graphql/execution/interpreter/resolve.rb +26 -0
  24. data/lib/graphql/execution/interpreter/runtime.rb +300 -222
  25. data/lib/graphql/execution/interpreter.rb +187 -78
  26. data/lib/graphql/execution/lazy.rb +7 -21
  27. data/lib/graphql/execution/lookahead.rb +44 -40
  28. data/lib/graphql/execution/multiplex.rb +3 -174
  29. data/lib/graphql/execution.rb +11 -4
  30. data/lib/graphql/filter.rb +7 -2
  31. data/lib/graphql/introspection/directive_type.rb +2 -2
  32. data/lib/graphql/introspection/dynamic_fields.rb +3 -8
  33. data/lib/graphql/introspection/entry_points.rb +2 -15
  34. data/lib/graphql/introspection/field_type.rb +1 -1
  35. data/lib/graphql/introspection/schema_type.rb +2 -2
  36. data/lib/graphql/introspection/type_type.rb +13 -6
  37. data/lib/graphql/introspection.rb +4 -3
  38. data/lib/graphql/language/document_from_schema_definition.rb +43 -44
  39. data/lib/graphql/language/lexer.rb +216 -1488
  40. data/lib/graphql/language/nodes.rb +66 -40
  41. data/lib/graphql/language/parser.rb +539 -510
  42. data/lib/graphql/language/parser.y +53 -44
  43. data/lib/graphql/language/printer.rb +37 -21
  44. data/lib/graphql/language/visitor.rb +191 -83
  45. data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
  46. data/lib/graphql/pagination/array_connection.rb +4 -2
  47. data/lib/graphql/pagination/connection.rb +33 -6
  48. data/lib/graphql/pagination/connections.rb +3 -28
  49. data/lib/graphql/pagination/relation_connection.rb +2 -0
  50. data/lib/graphql/query/context.rb +156 -196
  51. data/lib/graphql/query/input_validation_result.rb +10 -1
  52. data/lib/graphql/query/null_context.rb +1 -4
  53. data/lib/graphql/query/validation_pipeline.rb +12 -37
  54. data/lib/graphql/query/variable_validation_error.rb +2 -2
  55. data/lib/graphql/query/variables.rb +35 -21
  56. data/lib/graphql/query.rb +39 -46
  57. data/lib/graphql/railtie.rb +0 -104
  58. data/lib/graphql/rake_task/validate.rb +1 -1
  59. data/lib/graphql/rake_task.rb +29 -1
  60. data/lib/graphql/relay/range_add.rb +9 -20
  61. data/lib/graphql/relay.rb +0 -15
  62. data/lib/graphql/schema/addition.rb +7 -9
  63. data/lib/graphql/schema/argument.rb +38 -47
  64. data/lib/graphql/schema/build_from_definition.rb +47 -21
  65. data/lib/graphql/schema/directive/one_of.rb +12 -0
  66. data/lib/graphql/schema/directive/transform.rb +1 -1
  67. data/lib/graphql/schema/directive.rb +12 -23
  68. data/lib/graphql/schema/enum.rb +29 -41
  69. data/lib/graphql/schema/enum_value.rb +2 -25
  70. data/lib/graphql/schema/field/connection_extension.rb +4 -0
  71. data/lib/graphql/schema/field.rb +256 -349
  72. data/lib/graphql/schema/field_extension.rb +1 -4
  73. data/lib/graphql/schema/find_inherited_value.rb +2 -7
  74. data/lib/graphql/schema/input_object.rb +57 -69
  75. data/lib/graphql/schema/interface.rb +0 -35
  76. data/lib/graphql/schema/introspection_system.rb +3 -8
  77. data/lib/graphql/schema/late_bound_type.rb +8 -2
  78. data/lib/graphql/schema/list.rb +18 -9
  79. data/lib/graphql/schema/loader.rb +1 -2
  80. data/lib/graphql/schema/member/base_dsl_methods.rb +17 -19
  81. data/lib/graphql/schema/member/build_type.rb +5 -7
  82. data/lib/graphql/schema/member/has_arguments.rb +147 -56
  83. data/lib/graphql/schema/member/has_ast_node.rb +12 -0
  84. data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
  85. data/lib/graphql/schema/member/has_directives.rb +81 -61
  86. data/lib/graphql/schema/member/has_fields.rb +97 -40
  87. data/lib/graphql/schema/member/has_interfaces.rb +49 -10
  88. data/lib/graphql/schema/member/has_validators.rb +32 -6
  89. data/lib/graphql/schema/member/relay_shortcuts.rb +47 -2
  90. data/lib/graphql/schema/member/type_system_helpers.rb +17 -0
  91. data/lib/graphql/schema/member/validates_input.rb +3 -3
  92. data/lib/graphql/schema/member.rb +0 -6
  93. data/lib/graphql/schema/mutation.rb +0 -9
  94. data/lib/graphql/schema/non_null.rb +3 -9
  95. data/lib/graphql/schema/object.rb +15 -52
  96. data/lib/graphql/schema/relay_classic_mutation.rb +53 -42
  97. data/lib/graphql/schema/resolver/has_payload_type.rb +20 -10
  98. data/lib/graphql/schema/resolver.rb +43 -44
  99. data/lib/graphql/schema/scalar.rb +8 -23
  100. data/lib/graphql/schema/subscription.rb +0 -7
  101. data/lib/graphql/schema/timeout.rb +24 -28
  102. data/lib/graphql/schema/type_membership.rb +3 -0
  103. data/lib/graphql/schema/union.rb +10 -17
  104. data/lib/graphql/schema/validator.rb +1 -1
  105. data/lib/graphql/schema/warden.rb +37 -9
  106. data/lib/graphql/schema/wrapper.rb +0 -5
  107. data/lib/graphql/schema.rb +265 -968
  108. data/lib/graphql/static_validation/all_rules.rb +1 -0
  109. data/lib/graphql/static_validation/base_visitor.rb +4 -21
  110. data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
  111. data/lib/graphql/static_validation/error.rb +2 -2
  112. data/lib/graphql/static_validation/literal_validator.rb +19 -1
  113. data/lib/graphql/static_validation/rules/directives_are_defined.rb +11 -5
  114. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
  115. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
  116. data/lib/graphql/static_validation/rules/fields_will_merge.rb +2 -2
  117. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
  118. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
  119. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +12 -6
  120. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
  121. data/lib/graphql/static_validation/validator.rb +3 -25
  122. data/lib/graphql/static_validation.rb +0 -2
  123. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -1
  124. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
  125. data/lib/graphql/subscriptions/event.rb +3 -8
  126. data/lib/graphql/subscriptions/instrumentation.rb +0 -51
  127. data/lib/graphql/subscriptions.rb +32 -20
  128. data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
  129. data/lib/graphql/tracing/appoptics_trace.rb +231 -0
  130. data/lib/graphql/tracing/appsignal_trace.rb +77 -0
  131. data/lib/graphql/tracing/data_dog_trace.rb +148 -0
  132. data/lib/graphql/tracing/data_dog_tracing.rb +21 -2
  133. data/lib/graphql/tracing/legacy_trace.rb +65 -0
  134. data/lib/graphql/tracing/new_relic_trace.rb +75 -0
  135. data/lib/graphql/tracing/notifications_trace.rb +42 -0
  136. data/lib/graphql/tracing/platform_trace.rb +109 -0
  137. data/lib/graphql/tracing/platform_tracing.rb +33 -43
  138. data/lib/graphql/tracing/prometheus_trace.rb +89 -0
  139. data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +1 -1
  140. data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
  141. data/lib/graphql/tracing/scout_trace.rb +72 -0
  142. data/lib/graphql/tracing/statsd_trace.rb +56 -0
  143. data/lib/graphql/tracing/trace.rb +75 -0
  144. data/lib/graphql/tracing.rb +16 -40
  145. data/lib/graphql/type_kinds.rb +6 -3
  146. data/lib/graphql/types/iso_8601_date.rb +4 -1
  147. data/lib/graphql/types/iso_8601_date_time.rb +4 -0
  148. data/lib/graphql/types/relay/base_connection.rb +16 -6
  149. data/lib/graphql/types/relay/connection_behaviors.rb +29 -27
  150. data/lib/graphql/types/relay/edge_behaviors.rb +16 -5
  151. data/lib/graphql/types/relay/node_behaviors.rb +12 -2
  152. data/lib/graphql/types/relay/page_info_behaviors.rb +7 -2
  153. data/lib/graphql/types/relay.rb +0 -3
  154. data/lib/graphql/types/string.rb +1 -1
  155. data/lib/graphql/version.rb +1 -1
  156. data/lib/graphql.rb +17 -74
  157. metadata +33 -133
  158. data/lib/graphql/analysis/analyze_query.rb +0 -98
  159. data/lib/graphql/analysis/field_usage.rb +0 -45
  160. data/lib/graphql/analysis/max_query_complexity.rb +0 -26
  161. data/lib/graphql/analysis/max_query_depth.rb +0 -26
  162. data/lib/graphql/analysis/query_complexity.rb +0 -88
  163. data/lib/graphql/analysis/query_depth.rb +0 -43
  164. data/lib/graphql/analysis/reducer_state.rb +0 -48
  165. data/lib/graphql/argument.rb +0 -131
  166. data/lib/graphql/authorization.rb +0 -82
  167. data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
  168. data/lib/graphql/backwards_compatibility.rb +0 -61
  169. data/lib/graphql/base_type.rb +0 -232
  170. data/lib/graphql/boolean_type.rb +0 -2
  171. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
  172. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
  173. data/lib/graphql/compatibility/execution_specification.rb +0 -436
  174. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
  175. data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
  176. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
  177. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
  178. data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
  179. data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
  180. data/lib/graphql/compatibility.rb +0 -5
  181. data/lib/graphql/define/assign_argument.rb +0 -12
  182. data/lib/graphql/define/assign_connection.rb +0 -13
  183. data/lib/graphql/define/assign_enum_value.rb +0 -18
  184. data/lib/graphql/define/assign_global_id_field.rb +0 -11
  185. data/lib/graphql/define/assign_mutation_function.rb +0 -34
  186. data/lib/graphql/define/assign_object_field.rb +0 -42
  187. data/lib/graphql/define/defined_object_proxy.rb +0 -53
  188. data/lib/graphql/define/instance_definable.rb +0 -255
  189. data/lib/graphql/define/no_definition_error.rb +0 -7
  190. data/lib/graphql/define/non_null_with_bang.rb +0 -16
  191. data/lib/graphql/define/type_definer.rb +0 -31
  192. data/lib/graphql/define.rb +0 -31
  193. data/lib/graphql/deprecated_dsl.rb +0 -55
  194. data/lib/graphql/directive/deprecated_directive.rb +0 -2
  195. data/lib/graphql/directive/include_directive.rb +0 -2
  196. data/lib/graphql/directive/skip_directive.rb +0 -2
  197. data/lib/graphql/directive.rb +0 -107
  198. data/lib/graphql/enum_type.rb +0 -133
  199. data/lib/graphql/execution/execute.rb +0 -333
  200. data/lib/graphql/execution/flatten.rb +0 -40
  201. data/lib/graphql/execution/instrumentation.rb +0 -92
  202. data/lib/graphql/execution/lazy/resolve.rb +0 -91
  203. data/lib/graphql/execution/typecast.rb +0 -50
  204. data/lib/graphql/field/resolve.rb +0 -59
  205. data/lib/graphql/field.rb +0 -226
  206. data/lib/graphql/float_type.rb +0 -2
  207. data/lib/graphql/function.rb +0 -128
  208. data/lib/graphql/id_type.rb +0 -2
  209. data/lib/graphql/input_object_type.rb +0 -138
  210. data/lib/graphql/int_type.rb +0 -2
  211. data/lib/graphql/interface_type.rb +0 -72
  212. data/lib/graphql/internal_representation/document.rb +0 -27
  213. data/lib/graphql/internal_representation/node.rb +0 -206
  214. data/lib/graphql/internal_representation/print.rb +0 -51
  215. data/lib/graphql/internal_representation/rewrite.rb +0 -184
  216. data/lib/graphql/internal_representation/scope.rb +0 -88
  217. data/lib/graphql/internal_representation/visit.rb +0 -36
  218. data/lib/graphql/internal_representation.rb +0 -7
  219. data/lib/graphql/language/lexer.rl +0 -260
  220. data/lib/graphql/list_type.rb +0 -80
  221. data/lib/graphql/non_null_type.rb +0 -71
  222. data/lib/graphql/object_type.rb +0 -130
  223. data/lib/graphql/query/arguments.rb +0 -189
  224. data/lib/graphql/query/arguments_cache.rb +0 -24
  225. data/lib/graphql/query/executor.rb +0 -52
  226. data/lib/graphql/query/literal_input.rb +0 -136
  227. data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
  228. data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
  229. data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
  230. data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
  231. data/lib/graphql/query/serial_execution.rb +0 -40
  232. data/lib/graphql/relay/array_connection.rb +0 -83
  233. data/lib/graphql/relay/base_connection.rb +0 -189
  234. data/lib/graphql/relay/connection_instrumentation.rb +0 -54
  235. data/lib/graphql/relay/connection_resolve.rb +0 -43
  236. data/lib/graphql/relay/connection_type.rb +0 -54
  237. data/lib/graphql/relay/edge.rb +0 -27
  238. data/lib/graphql/relay/edge_type.rb +0 -19
  239. data/lib/graphql/relay/edges_instrumentation.rb +0 -39
  240. data/lib/graphql/relay/global_id_resolve.rb +0 -17
  241. data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
  242. data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
  243. data/lib/graphql/relay/mutation/resolve.rb +0 -56
  244. data/lib/graphql/relay/mutation/result.rb +0 -38
  245. data/lib/graphql/relay/mutation.rb +0 -106
  246. data/lib/graphql/relay/node.rb +0 -39
  247. data/lib/graphql/relay/page_info.rb +0 -7
  248. data/lib/graphql/relay/relation_connection.rb +0 -188
  249. data/lib/graphql/relay/type_extensions.rb +0 -32
  250. data/lib/graphql/scalar_type.rb +0 -91
  251. data/lib/graphql/schema/catchall_middleware.rb +0 -35
  252. data/lib/graphql/schema/default_parse_error.rb +0 -10
  253. data/lib/graphql/schema/default_type_error.rb +0 -17
  254. data/lib/graphql/schema/member/accepts_definition.rb +0 -164
  255. data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
  256. data/lib/graphql/schema/member/instrumentation.rb +0 -131
  257. data/lib/graphql/schema/middleware_chain.rb +0 -82
  258. data/lib/graphql/schema/possible_types.rb +0 -44
  259. data/lib/graphql/schema/rescue_middleware.rb +0 -60
  260. data/lib/graphql/schema/timeout_middleware.rb +0 -88
  261. data/lib/graphql/schema/traversal.rb +0 -228
  262. data/lib/graphql/schema/validation.rb +0 -313
  263. data/lib/graphql/static_validation/default_visitor.rb +0 -15
  264. data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
  265. data/lib/graphql/string_type.rb +0 -2
  266. data/lib/graphql/subscriptions/subscription_root.rb +0 -76
  267. data/lib/graphql/tracing/skylight_tracing.rb +0 -70
  268. data/lib/graphql/types/relay/default_relay.rb +0 -31
  269. data/lib/graphql/types/relay/node_field.rb +0 -24
  270. data/lib/graphql/types/relay/nodes_field.rb +0 -43
  271. data/lib/graphql/union_type.rb +0 -115
  272. data/lib/graphql/upgrader/member.rb +0 -937
  273. data/lib/graphql/upgrader/schema.rb +0 -38
@@ -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
@@ -293,8 +311,8 @@ module GraphQL
293
311
  # (`nil` means "unlimited max page size".)
294
312
  # @param max_page_size [Integer, nil] Set a new value
295
313
  # @return [Integer, nil] The `max_page_size` assigned to fields that use this resolver
296
- def max_page_size(new_max_page_size = :not_given)
297
- if new_max_page_size != :not_given
314
+ def max_page_size(new_max_page_size = NOT_CONFIGURED)
315
+ if new_max_page_size != NOT_CONFIGURED
298
316
  @max_page_size = new_max_page_size
299
317
  elsif defined?(@max_page_size)
300
318
  @max_page_size
@@ -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_CONFIGURED)
336
+ if new_default_page_size != NOT_CONFIGURED
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
@@ -33,60 +33,56 @@ module GraphQL
33
33
  # end
34
34
  #
35
35
  class Timeout
36
- def self.use(schema, **options)
37
- tracer = new(**options)
38
- schema.tracer(tracer)
36
+ def self.use(schema, max_seconds: nil)
37
+ timeout = self.new(max_seconds: max_seconds)
38
+ schema.trace_with(self::Trace, timeout: timeout)
39
39
  end
40
40
 
41
- # @param max_seconds [Numeric] how many seconds the query should be allowed to resolve new fields
42
41
  def initialize(max_seconds:)
43
42
  @max_seconds = max_seconds
44
43
  end
45
44
 
46
- def trace(key, data)
47
- case key
48
- when 'execute_multiplex'
49
- data.fetch(:multiplex).queries.each do |query|
50
- timeout_duration_s = max_seconds(query)
45
+ module Trace
46
+ # @param max_seconds [Numeric] how many seconds the query should be allowed to resolve new fields
47
+ def initialize(timeout:, **rest)
48
+ @timeout = timeout
49
+ super
50
+ end
51
+
52
+ def execute_multiplex(multiplex:)
53
+ multiplex.queries.each do |query|
54
+ timeout_duration_s = @timeout.max_seconds(query)
51
55
  timeout_state = if timeout_duration_s == false
52
56
  # if the method returns `false`, don't apply a timeout
53
57
  false
54
58
  else
55
59
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
56
- timeout_at = now + (max_seconds(query) * 1000)
60
+ timeout_at = now + (timeout_duration_s * 1000)
57
61
  {
58
62
  timeout_at: timeout_at,
59
63
  timed_out: false
60
64
  }
61
65
  end
62
- query.context.namespace(self.class)[:state] = timeout_state
66
+ query.context.namespace(@timeout)[:state] = timeout_state
63
67
  end
68
+ super
69
+ end
64
70
 
65
- yield
66
- when 'execute_field', 'execute_field_lazy'
67
- query_context = data[:context] || data[:query].context
68
- timeout_state = query_context.namespace(self.class).fetch(:state)
71
+ def execute_field(query:, field:, **_rest)
72
+ timeout_state = query.context.namespace(@timeout).fetch(:state)
69
73
  # If the `:state` is `false`, then `max_seconds(query)` opted out of timeout for this query.
70
74
  if timeout_state != false && Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) > timeout_state.fetch(:timeout_at)
71
- error = if data[:context]
72
- GraphQL::Schema::Timeout::TimeoutError.new(query_context.parent_type, query_context.field)
73
- else
74
- field = data.fetch(:field)
75
- GraphQL::Schema::Timeout::TimeoutError.new(field.owner, field)
76
- end
77
-
75
+ error = GraphQL::Schema::Timeout::TimeoutError.new(field)
78
76
  # Only invoke the timeout callback for the first timeout
79
77
  if !timeout_state[:timed_out]
80
78
  timeout_state[:timed_out] = true
81
- handle_timeout(error, query_context.query)
79
+ @timeout.handle_timeout(error, query)
82
80
  end
83
81
 
84
82
  error
85
83
  else
86
- yield
84
+ super
87
85
  end
88
- else
89
- yield
90
86
  end
91
87
  end
92
88
 
@@ -114,8 +110,8 @@ module GraphQL
114
110
  # to take this error and raise a new one which _doesn't_ descend from {GraphQL::ExecutionError},
115
111
  # such as `RuntimeError`.
116
112
  class TimeoutError < GraphQL::ExecutionError
117
- def initialize(parent_type, field)
118
- super("Timeout on #{parent_type.graphql_name}.#{field.graphql_name}")
113
+ def initialize(field)
114
+ super("Timeout on #{field.path}")
119
115
  end
120
116
  end
121
117
  end
@@ -11,6 +11,9 @@ module GraphQL
11
11
  # @return [Class<GraphQL::Schema::Union>, Module<GraphQL::Schema::Interface>]
12
12
  attr_reader :abstract_type
13
13
 
14
+ # @return [Hash]
15
+ attr_reader :options
16
+
14
17
  # Called when an object is hooked up to an abstract type, such as {Schema::Union.possible_types}
15
18
  # or {Schema::Object.implements} (for interfaces).
16
19
  #
@@ -2,7 +2,6 @@
2
2
  module GraphQL
3
3
  class Schema
4
4
  class Union < GraphQL::Schema::Member
5
- extend GraphQL::Schema::Member::AcceptsDefinition
6
5
  extend GraphQL::Schema::Member::HasUnresolvedTypeError
7
6
 
8
7
  class << self
@@ -33,21 +32,6 @@ module GraphQL
33
32
  type_memberships.map(&:object_type)
34
33
  end
35
34
 
36
- prepend GraphQL::Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
37
-
38
- def to_graphql
39
- type_defn = GraphQL::UnionType.new
40
- type_defn.name = graphql_name
41
- type_defn.description = description
42
- type_defn.ast_node = ast_node
43
- type_defn.type_memberships = type_memberships
44
- if respond_to?(:resolve_type)
45
- type_defn.resolve_type = method(:resolve_type)
46
- end
47
- type_defn.metadata[:type_class] = self
48
- type_defn
49
- end
50
-
51
35
  def type_membership_class(membership_class = nil)
52
36
  if membership_class
53
37
  @type_membership_class = membership_class
@@ -86,9 +70,18 @@ module GraphQL
86
70
  private
87
71
 
88
72
  def assert_valid_union_member(type_defn)
89
- if type_defn.is_a?(Module) && !type_defn.is_a?(Class)
73
+ case type_defn
74
+ when Class
75
+ if !type_defn.kind.object?
76
+ raise ArgumentError, "Union possible_types can only be object types (not #{type_defn.kind.name}, #{type_defn.inspect})"
77
+ end
78
+ when Module
90
79
  # it's an interface type, defined as a module
91
80
  raise ArgumentError, "Union possible_types can only be object types (not interface types), remove #{type_defn.graphql_name} (#{type_defn.inspect})"
81
+ when String, GraphQL::Schema::LateBoundType
82
+ # Ok - assume it will get checked later
83
+ else
84
+ raise ArgumentError, "Union possible_types can only be class-based GraphQL types (not #{type_defn.inspect} (#{type_defn.class.name}))."
92
85
  end
93
86
  end
94
87
  end
@@ -102,7 +102,7 @@ module GraphQL
102
102
 
103
103
  self.all_validators = {}
104
104
 
105
- include Schema::FindInheritedValue::EmptyObjects
105
+ include GraphQL::EmptyObjects
106
106
 
107
107
  class ValidationFailedError < GraphQL::ExecutionError
108
108
  attr_reader :errors
@@ -10,7 +10,7 @@ module GraphQL
10
10
  # should go through a warden. If you access the schema directly,
11
11
  # you may show a client something that it shouldn't be allowed to see.
12
12
  #
13
- # @example Hidding private fields
13
+ # @example Hiding private fields
14
14
  # private_members = -> (member, ctx) { member.metadata[:private] }
15
15
  # result = Schema.execute(query_string, except: private_members)
16
16
  #
@@ -38,7 +38,9 @@ module GraphQL
38
38
  # @api private
39
39
  class Warden
40
40
  def self.from_context(context)
41
- (context.respond_to?(:warden) && context.warden) || PassThruWarden
41
+ context.warden # this might be a hash which won't respond to this
42
+ rescue
43
+ PassThruWarden
42
44
  end
43
45
 
44
46
  # @param visibility_method [Symbol] a Warden method to call for this entry
@@ -55,7 +57,9 @@ module GraphQL
55
57
  if visible_item.nil?
56
58
  visible_item = item
57
59
  else
58
- raise Schema::DuplicateNamesError, "Found two visible definitions for `#{item.path}`: #{visible_item.inspect}, #{item.inspect}"
60
+ raise DuplicateNamesError.new(
61
+ duplicated_name: item.path, duplicated_definition_1: visible_item.inspect, duplicated_definition_2: item.inspect
62
+ )
59
63
  end
60
64
  end
61
65
  end
@@ -78,6 +82,8 @@ module GraphQL
78
82
  def visible_type?(type, ctx); type.visible?(ctx); end
79
83
  def visible_enum_value?(ev, ctx); ev.visible?(ctx); end
80
84
  def visible_type_membership?(tm, ctx); tm.visible?(ctx); end
85
+ def interface_type_memberships(obj_t, ctx); obj_t.interface_type_memberships; end
86
+ def arguments(owner, ctx); owner.arguments(ctx); end
81
87
  end
82
88
  end
83
89
 
@@ -85,13 +91,20 @@ module GraphQL
85
91
  # @param context [GraphQL::Query::Context]
86
92
  # @param schema [GraphQL::Schema]
87
93
  def initialize(filter, context:, schema:)
88
- @schema = schema.interpreter? ? schema : schema.graphql_definition
94
+ @schema = schema
89
95
  # Cache these to avoid repeated hits to the inheritance chain when one isn't present
90
96
  @query = @schema.query
91
97
  @mutation = @schema.mutation
92
98
  @subscription = @schema.subscription
93
99
  @context = context
94
100
  @visibility_cache = read_through { |m| filter.call(m, context) }
101
+ # Initialize all ivars to improve object shape consistency:
102
+ @types = @visible_types = @reachable_types = @visible_parent_fields =
103
+ @visible_possible_types = @visible_fields = @visible_arguments = @visible_enum_arrays =
104
+ @visible_enum_values = @visible_interfaces = @type_visibility = @type_memberships =
105
+ @visible_and_reachable_type = @unions = @unfiltered_interfaces = @references_to =
106
+ @reachable_type_set =
107
+ nil
95
108
  end
96
109
 
97
110
  # @return [Hash<String, GraphQL::BaseType>] Visible types in the schema
@@ -172,14 +185,20 @@ module GraphQL
172
185
 
173
186
  # @param argument_owner [GraphQL::Field, GraphQL::InputObjectType]
174
187
  # @return [Array<GraphQL::Argument>] Visible arguments on `argument_owner`
175
- def arguments(argument_owner)
176
- @visible_arguments ||= read_through { |o| o.arguments(@context).each_value.select { |a| visible_argument?(a) } }
188
+ def arguments(argument_owner, ctx = nil)
189
+ @visible_arguments ||= read_through { |o| o.arguments(@context).each_value.select { |a| visible_argument?(a, @context) } }
177
190
  @visible_arguments[argument_owner]
178
191
  end
179
192
 
180
193
  # @return [Array<GraphQL::EnumType::EnumValue>] Visible members of `enum_defn`
181
194
  def enum_values(enum_defn)
182
- @visible_enum_arrays ||= read_through { |e| e.enum_values(@context) }
195
+ @visible_enum_arrays ||= read_through { |e|
196
+ values = e.enum_values(@context)
197
+ if values.size == 0
198
+ raise GraphQL::Schema::Enum::MissingValuesError.new(e)
199
+ end
200
+ values
201
+ }
183
202
  @visible_enum_arrays[enum_defn]
184
203
  end
185
204
 
@@ -231,6 +250,13 @@ module GraphQL
231
250
  visible?(type_membership)
232
251
  end
233
252
 
253
+ def interface_type_memberships(obj_type, _ctx = nil)
254
+ @type_memberships ||= read_through do |obj_t|
255
+ obj_t.interface_type_memberships
256
+ end
257
+ @type_memberships[obj_type]
258
+ end
259
+
234
260
  private
235
261
 
236
262
  def visible_and_reachable_type?(type_defn)
@@ -330,7 +356,7 @@ module GraphQL
330
356
  end
331
357
 
332
358
  def reachable_type_set
333
- return @reachable_type_set if defined?(@reachable_type_set)
359
+ return @reachable_type_set if @reachable_type_set
334
360
 
335
361
  @reachable_type_set = Set.new
336
362
  rt_hash = {}
@@ -362,7 +388,9 @@ module GraphQL
362
388
  if @reachable_type_set.add?(type)
363
389
  type_by_name = rt_hash[type.graphql_name] ||= type
364
390
  if type_by_name != type
365
- raise DuplicateNamesError, "Found two visible type definitions for `#{type.graphql_name}`: #{type.inspect}, #{type_by_name.inspect}"
391
+ raise DuplicateNamesError.new(
392
+ duplicated_name: type.graphql_name, duplicated_definition_1: type.inspect, duplicated_definition_2: type_by_name.inspect
393
+ )
366
394
  end
367
395
  if type.kind.input_object?
368
396
  # recurse into visible arguments