graphql 2.6.14 → 2.6.16

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.
Files changed (381) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/core.rb +1 -0
  3. data/lib/generators/graphql/detailed_trace_generator.rb +1 -0
  4. data/lib/generators/graphql/enum_generator.rb +1 -0
  5. data/lib/generators/graphql/field_extractor.rb +1 -0
  6. data/lib/generators/graphql/input_generator.rb +1 -0
  7. data/lib/generators/graphql/install/mutation_root_generator.rb +1 -0
  8. data/lib/generators/graphql/install_generator.rb +1 -0
  9. data/lib/generators/graphql/interface_generator.rb +1 -0
  10. data/lib/generators/graphql/loader_generator.rb +1 -0
  11. data/lib/generators/graphql/mutation_create_generator.rb +1 -0
  12. data/lib/generators/graphql/mutation_delete_generator.rb +1 -0
  13. data/lib/generators/graphql/mutation_generator.rb +1 -0
  14. data/lib/generators/graphql/mutation_update_generator.rb +1 -0
  15. data/lib/generators/graphql/object_generator.rb +1 -0
  16. data/lib/generators/graphql/orm_mutations_base.rb +1 -0
  17. data/lib/generators/graphql/relay.rb +1 -0
  18. data/lib/generators/graphql/relay_generator.rb +1 -0
  19. data/lib/generators/graphql/scalar_generator.rb +1 -0
  20. data/lib/generators/graphql/templates/graphql_controller.erb +7 -1
  21. data/lib/generators/graphql/type_generator.rb +1 -0
  22. data/lib/generators/graphql/union_generator.rb +1 -0
  23. data/lib/graphql/analysis/analyzer.rb +1 -0
  24. data/lib/graphql/analysis/field_usage.rb +1 -0
  25. data/lib/graphql/analysis/max_query_complexity.rb +3 -1
  26. data/lib/graphql/analysis/max_query_depth.rb +3 -1
  27. data/lib/graphql/analysis/query_complexity.rb +7 -2
  28. data/lib/graphql/analysis/query_depth.rb +2 -1
  29. data/lib/graphql/analysis/visitor.rb +15 -2
  30. data/lib/graphql/analysis.rb +5 -5
  31. data/lib/graphql/analysis_error.rb +2 -1
  32. data/lib/graphql/autoload.rb +1 -0
  33. data/lib/graphql/backtrace/table.rb +1 -0
  34. data/lib/graphql/backtrace/traced_error.rb +1 -0
  35. data/lib/graphql/backtrace.rb +1 -0
  36. data/lib/graphql/coercion_error.rb +2 -1
  37. data/lib/graphql/current.rb +6 -1
  38. data/lib/graphql/dashboard/application_controller.rb +1 -0
  39. data/lib/graphql/dashboard/detailed_traces.rb +1 -0
  40. data/lib/graphql/dashboard/installable.rb +1 -0
  41. data/lib/graphql/dashboard/landings_controller.rb +1 -0
  42. data/lib/graphql/dashboard/limiters.rb +1 -0
  43. data/lib/graphql/dashboard/operation_store.rb +1 -0
  44. data/lib/graphql/dashboard/statics_controller.rb +1 -0
  45. data/lib/graphql/dashboard/subscriptions.rb +1 -0
  46. data/lib/graphql/dashboard.rb +2 -1
  47. data/lib/graphql/dataloader/active_record_association_source.rb +1 -0
  48. data/lib/graphql/dataloader/active_record_source.rb +1 -0
  49. data/lib/graphql/dataloader/async_dataloader.rb +1 -0
  50. data/lib/graphql/dataloader/null_dataloader.rb +1 -0
  51. data/lib/graphql/dataloader/request.rb +1 -0
  52. data/lib/graphql/dataloader/request_all.rb +1 -0
  53. data/lib/graphql/dataloader/source.rb +1 -0
  54. data/lib/graphql/dataloader.rb +1 -0
  55. data/lib/graphql/date_encoding_error.rb +4 -1
  56. data/lib/graphql/dig.rb +1 -0
  57. data/lib/graphql/duration_encoding_error.rb +4 -1
  58. data/lib/graphql/execution/directive_checks.rb +3 -1
  59. data/lib/graphql/execution/errors.rb +19 -7
  60. data/lib/graphql/execution/field_resolve_step.rb +4 -3
  61. data/lib/graphql/execution/finalize.rb +1 -0
  62. data/lib/graphql/execution/input_values.rb +196 -120
  63. data/lib/graphql/execution/interpreter/argument_value.rb +1 -0
  64. data/lib/graphql/execution/interpreter/arguments.rb +1 -0
  65. data/lib/graphql/execution/interpreter/arguments_cache.rb +1 -0
  66. data/lib/graphql/execution/interpreter/execution_errors.rb +7 -4
  67. data/lib/graphql/execution/interpreter/handles_raw_value.rb +6 -2
  68. data/lib/graphql/execution/interpreter/resolve.rb +6 -2
  69. data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +1 -0
  70. data/lib/graphql/execution/interpreter/runtime.rb +14 -8
  71. data/lib/graphql/execution/interpreter.rb +7 -4
  72. data/lib/graphql/execution/lazy/lazy_method_map.rb +1 -0
  73. data/lib/graphql/execution/lazy.rb +1 -0
  74. data/lib/graphql/execution/load_argument_step.rb +1 -0
  75. data/lib/graphql/execution/lookahead.rb +21 -8
  76. data/lib/graphql/execution/multiplex.rb +1 -0
  77. data/lib/graphql/execution/next.rb +2 -0
  78. data/lib/graphql/execution/prepare_object_step.rb +3 -5
  79. data/lib/graphql/execution/resolve_type_step.rb +1 -0
  80. data/lib/graphql/execution/runner.rb +21 -12
  81. data/lib/graphql/execution/selections_step.rb +2 -1
  82. data/lib/graphql/execution/variable_values.rb +262 -0
  83. data/lib/graphql/execution.rb +1 -0
  84. data/lib/graphql/execution_error.rb +1 -0
  85. data/lib/graphql/float_decoding_error.rb +4 -1
  86. data/lib/graphql/float_encoding_error.rb +1 -0
  87. data/lib/graphql/integer_decoding_error.rb +4 -1
  88. data/lib/graphql/integer_encoding_error.rb +1 -0
  89. data/lib/graphql/introspection/base_object.rb +2 -1
  90. data/lib/graphql/introspection/directive_location_enum.rb +2 -1
  91. data/lib/graphql/introspection/directive_type.rb +4 -1
  92. data/lib/graphql/introspection/dynamic_fields.rb +4 -1
  93. data/lib/graphql/introspection/entry_points.rb +1 -0
  94. data/lib/graphql/introspection/enum_value_type.rb +4 -1
  95. data/lib/graphql/introspection/field_type.rb +6 -1
  96. data/lib/graphql/introspection/input_value_type.rb +1 -0
  97. data/lib/graphql/introspection/introspection_query.rb +10 -7
  98. data/lib/graphql/introspection/schema_type.rb +1 -0
  99. data/lib/graphql/introspection/type_kind_enum.rb +2 -1
  100. data/lib/graphql/introspection/type_type.rb +1 -0
  101. data/lib/graphql/introspection.rb +3 -1
  102. data/lib/graphql/invalid_name_error.rb +1 -0
  103. data/lib/graphql/invalid_null_error.rb +1 -0
  104. data/lib/graphql/language/block_string.rb +12 -5
  105. data/lib/graphql/language/cache.rb +1 -0
  106. data/lib/graphql/language/comment.rb +3 -1
  107. data/lib/graphql/language/definition_slice.rb +1 -0
  108. data/lib/graphql/language/document_from_schema_definition.rb +1 -0
  109. data/lib/graphql/language/generation.rb +3 -1
  110. data/lib/graphql/language/lexer.rb +33 -25
  111. data/lib/graphql/language/nodes.rb +1 -0
  112. data/lib/graphql/language/parser.rb +11 -7
  113. data/lib/graphql/language/printer.rb +1 -0
  114. data/lib/graphql/language/sanitized_printer.rb +1 -0
  115. data/lib/graphql/language/static_visitor.rb +1 -0
  116. data/lib/graphql/language/visitor.rb +1 -0
  117. data/lib/graphql/language.rb +2 -1
  118. data/lib/graphql/load_application_object_failed_error.rb +1 -0
  119. data/lib/graphql/name_validator.rb +3 -1
  120. data/lib/graphql/pagination/active_record_relation_connection.rb +9 -1
  121. data/lib/graphql/pagination/array_connection.rb +1 -0
  122. data/lib/graphql/pagination/connection.rb +1 -0
  123. data/lib/graphql/pagination/connections.rb +1 -0
  124. data/lib/graphql/pagination/mongoid_relation_connection.rb +6 -1
  125. data/lib/graphql/pagination/relation_connection.rb +5 -4
  126. data/lib/graphql/pagination/sequel_dataset_connection.rb +6 -1
  127. data/lib/graphql/pagination.rb +2 -1
  128. data/lib/graphql/parse_error.rb +1 -0
  129. data/lib/graphql/query/context/scoped_context.rb +1 -0
  130. data/lib/graphql/query/context.rb +1 -0
  131. data/lib/graphql/query/fingerprint.rb +3 -1
  132. data/lib/graphql/query/input_validation_result.rb +44 -0
  133. data/lib/graphql/query/null_context.rb +1 -0
  134. data/lib/graphql/query/partial.rb +5 -0
  135. data/lib/graphql/query/result.rb +1 -0
  136. data/lib/graphql/query/validation_pipeline.rb +1 -0
  137. data/lib/graphql/query/variable_validation_error.rb +1 -0
  138. data/lib/graphql/query.rb +9 -12
  139. data/lib/graphql/railtie.rb +2 -1
  140. data/lib/graphql/rake_task/validate.rb +1 -0
  141. data/lib/graphql/rake_task.rb +1 -0
  142. data/lib/graphql/relay/range_add.rb +1 -0
  143. data/lib/graphql/relay.rb +2 -1
  144. data/lib/graphql/rubocop/graphql/base_cop.rb +1 -0
  145. data/lib/graphql/rubocop/graphql/default_null_true.rb +1 -0
  146. data/lib/graphql/rubocop/graphql/default_required_true.rb +1 -0
  147. data/lib/graphql/rubocop/graphql/field_type_in_block.rb +1 -0
  148. data/lib/graphql/rubocop/graphql/root_types_in_block.rb +1 -0
  149. data/lib/graphql/rubocop.rb +2 -1
  150. data/lib/graphql/runtime_error.rb +2 -1
  151. data/lib/graphql/runtime_type_error.rb +2 -1
  152. data/lib/graphql/schema/addition.rb +1 -0
  153. data/lib/graphql/schema/always_visible.rb +4 -1
  154. data/lib/graphql/schema/argument.rb +1 -0
  155. data/lib/graphql/schema/base_64_encoder.rb +4 -1
  156. data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +6 -3
  157. data/lib/graphql/schema/build_from_definition/resolve_map.rb +1 -0
  158. data/lib/graphql/schema/build_from_definition.rb +1 -0
  159. data/lib/graphql/schema/built_in_types.rb +3 -2
  160. data/lib/graphql/schema/directive/deprecated.rb +2 -1
  161. data/lib/graphql/schema/directive/feature.rb +1 -0
  162. data/lib/graphql/schema/directive/flagged.rb +5 -1
  163. data/lib/graphql/schema/directive/include.rb +3 -1
  164. data/lib/graphql/schema/directive/one_of.rb +5 -2
  165. data/lib/graphql/schema/directive/skip.rb +3 -1
  166. data/lib/graphql/schema/directive/specified_by.rb +2 -1
  167. data/lib/graphql/schema/directive/transform.rb +9 -4
  168. data/lib/graphql/schema/directive.rb +1 -0
  169. data/lib/graphql/schema/enum.rb +1 -0
  170. data/lib/graphql/schema/enum_value.rb +1 -0
  171. data/lib/graphql/schema/field/connection_extension.rb +6 -2
  172. data/lib/graphql/schema/field/scope_extension.rb +3 -1
  173. data/lib/graphql/schema/field.rb +4 -0
  174. data/lib/graphql/schema/field_extension.rb +1 -0
  175. data/lib/graphql/schema/find_inherited_value.rb +6 -1
  176. data/lib/graphql/schema/finder.rb +1 -0
  177. data/lib/graphql/schema/has_single_input_argument.rb +1 -0
  178. data/lib/graphql/schema/input_object.rb +1 -0
  179. data/lib/graphql/schema/interface.rb +1 -0
  180. data/lib/graphql/schema/introspection_system.rb +1 -0
  181. data/lib/graphql/schema/late_bound_type.rb +1 -0
  182. data/lib/graphql/schema/list.rb +1 -0
  183. data/lib/graphql/schema/loader.rb +1 -0
  184. data/lib/graphql/schema/member/base_dsl_methods.rb +1 -0
  185. data/lib/graphql/schema/member/build_type.rb +1 -0
  186. data/lib/graphql/schema/member/graphql_type_names.rb +2 -1
  187. data/lib/graphql/schema/member/has_arguments.rb +1 -0
  188. data/lib/graphql/schema/member/has_ast_node.rb +7 -2
  189. data/lib/graphql/schema/member/has_authorization.rb +7 -4
  190. data/lib/graphql/schema/member/has_dataloader.rb +1 -0
  191. data/lib/graphql/schema/member/has_deprecation_reason.rb +7 -2
  192. data/lib/graphql/schema/member/has_directives.rb +21 -22
  193. data/lib/graphql/schema/member/has_fields.rb +1 -0
  194. data/lib/graphql/schema/member/has_interfaces.rb +1 -0
  195. data/lib/graphql/schema/member/has_path.rb +3 -1
  196. data/lib/graphql/schema/member/has_unresolved_type_error.rb +3 -1
  197. data/lib/graphql/schema/member/has_validators.rb +1 -0
  198. data/lib/graphql/schema/member/relay_shortcuts.rb +1 -0
  199. data/lib/graphql/schema/member/scoped.rb +7 -3
  200. data/lib/graphql/schema/member/type_system_helpers.rb +1 -0
  201. data/lib/graphql/schema/member/validates_input.rb +7 -1
  202. data/lib/graphql/schema/member.rb +4 -2
  203. data/lib/graphql/schema/mutation.rb +7 -1
  204. data/lib/graphql/schema/non_null.rb +1 -0
  205. data/lib/graphql/schema/object.rb +2 -1
  206. data/lib/graphql/schema/printer.rb +1 -0
  207. data/lib/graphql/schema/ractor_shareable.rb +1 -0
  208. data/lib/graphql/schema/relay_classic_mutation.rb +8 -3
  209. data/lib/graphql/schema/resolver/has_payload_type.rb +1 -0
  210. data/lib/graphql/schema/resolver.rb +5 -3
  211. data/lib/graphql/schema/scalar.rb +27 -3
  212. data/lib/graphql/schema/subscription.rb +1 -0
  213. data/lib/graphql/schema/timeout.rb +1 -0
  214. data/lib/graphql/schema/type_expression.rb +4 -1
  215. data/lib/graphql/schema/type_membership.rb +1 -0
  216. data/lib/graphql/schema/union.rb +1 -0
  217. data/lib/graphql/schema/unique_within_type.rb +1 -0
  218. data/lib/graphql/schema/validator/all_validator.rb +7 -3
  219. data/lib/graphql/schema/validator/allow_blank_validator.rb +5 -2
  220. data/lib/graphql/schema/validator/allow_null_validator.rb +6 -3
  221. data/lib/graphql/schema/validator/exclusion_validator.rb +7 -4
  222. data/lib/graphql/schema/validator/format_validator.rb +7 -4
  223. data/lib/graphql/schema/validator/inclusion_validator.rb +6 -3
  224. data/lib/graphql/schema/validator/length_validator.rb +1 -0
  225. data/lib/graphql/schema/validator/numericality_validator.rb +1 -0
  226. data/lib/graphql/schema/validator/required_validator.rb +1 -0
  227. data/lib/graphql/schema/validator.rb +3 -2
  228. data/lib/graphql/schema/visibility/migration.rb +1 -0
  229. data/lib/graphql/schema/visibility/profile.rb +1 -0
  230. data/lib/graphql/schema/visibility/visit.rb +1 -0
  231. data/lib/graphql/schema/visibility.rb +1 -0
  232. data/lib/graphql/schema/warden.rb +1 -0
  233. data/lib/graphql/schema/wrapper.rb +1 -0
  234. data/lib/graphql/schema.rb +1 -0
  235. data/lib/graphql/static_validation/all_rules.rb +2 -1
  236. data/lib/graphql/static_validation/base_visitor.rb +126 -53
  237. data/lib/graphql/static_validation/definition_dependencies.rb +15 -2
  238. data/lib/graphql/static_validation/error.rb +14 -5
  239. data/lib/graphql/static_validation/interpreter_visitor.rb +2 -1
  240. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +9 -3
  241. data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +16 -8
  242. data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +5 -1
  243. data/lib/graphql/static_validation/rules/argument_names_are_unique_error.rb +8 -3
  244. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +10 -4
  245. data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +14 -6
  246. data/lib/graphql/static_validation/rules/directives_are_defined.rb +7 -9
  247. data/lib/graphql/static_validation/rules/directives_are_defined_error.rb +8 -3
  248. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +14 -7
  249. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations_error.rb +10 -4
  250. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +9 -4
  251. data/lib/graphql/static_validation/rules/fields_are_defined_on_type_error.rb +10 -4
  252. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -0
  253. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +10 -4
  254. data/lib/graphql/static_validation/rules/fields_will_merge.rb +2 -3
  255. data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +15 -4
  256. data/lib/graphql/static_validation/rules/fragment_names_are_unique.rb +10 -5
  257. data/lib/graphql/static_validation/rules/fragment_names_are_unique_error.rb +8 -3
  258. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +30 -14
  259. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +12 -5
  260. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +11 -6
  261. data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +8 -3
  262. data/lib/graphql/static_validation/rules/fragments_are_finite.rb +3 -1
  263. data/lib/graphql/static_validation/rules/fragments_are_finite_error.rb +8 -3
  264. data/lib/graphql/static_validation/rules/fragments_are_named.rb +3 -1
  265. data/lib/graphql/static_validation/rules/fragments_are_named_error.rb +5 -1
  266. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +7 -3
  267. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types_error.rb +8 -4
  268. data/lib/graphql/static_validation/rules/fragments_are_used.rb +3 -1
  269. data/lib/graphql/static_validation/rules/fragments_are_used_error.rb +8 -3
  270. data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +4 -1
  271. data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +8 -3
  272. data/lib/graphql/static_validation/rules/mutation_root_exists.rb +4 -2
  273. data/lib/graphql/static_validation/rules/mutation_root_exists_error.rb +5 -1
  274. data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +7 -3
  275. data/lib/graphql/static_validation/rules/no_definitions_are_present_error.rb +5 -1
  276. data/lib/graphql/static_validation/rules/not_single_subscription_error.rb +5 -1
  277. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +19 -6
  278. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +7 -2
  279. data/lib/graphql/static_validation/rules/operation_names_are_valid.rb +10 -4
  280. data/lib/graphql/static_validation/rules/operation_names_are_valid_error.rb +7 -2
  281. data/lib/graphql/static_validation/rules/query_root_exists.rb +4 -2
  282. data/lib/graphql/static_validation/rules/query_root_exists_error.rb +5 -1
  283. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +19 -10
  284. data/lib/graphql/static_validation/rules/required_arguments_are_present_error.rb +12 -5
  285. data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -1
  286. data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present_error.rb +11 -4
  287. data/lib/graphql/static_validation/rules/subscription_root_exists_and_single_subscription_selection.rb +9 -6
  288. data/lib/graphql/static_validation/rules/subscription_root_exists_error.rb +5 -1
  289. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +7 -5
  290. data/lib/graphql/static_validation/rules/unique_directives_per_location_error.rb +8 -3
  291. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +3 -1
  292. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb +13 -6
  293. data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +3 -1
  294. data/lib/graphql/static_validation/rules/variable_names_are_unique_error.rb +8 -3
  295. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +17 -9
  296. data/lib/graphql/static_validation/rules/variable_usages_are_allowed_error.rb +14 -6
  297. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +9 -6
  298. data/lib/graphql/static_validation/rules/variables_are_input_types_error.rb +10 -4
  299. data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +1 -0
  300. data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +11 -5
  301. data/lib/graphql/static_validation/validation_context.rb +52 -14
  302. data/lib/graphql/static_validation/validation_timeout_error.rb +5 -1
  303. data/lib/graphql/static_validation/validator.rb +7 -3
  304. data/lib/graphql/static_validation.rb +2 -2
  305. data/lib/graphql/string_encoding_error.rb +1 -0
  306. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +15 -13
  307. data/lib/graphql/subscriptions/broadcast_analyzer.rb +1 -0
  308. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +1 -0
  309. data/lib/graphql/subscriptions/event.rb +1 -0
  310. data/lib/graphql/subscriptions/serialize.rb +1 -0
  311. data/lib/graphql/subscriptions.rb +1 -0
  312. data/lib/graphql/testing/helpers.rb +1 -0
  313. data/lib/graphql/testing/mock_action_cable.rb +1 -0
  314. data/lib/graphql/testing.rb +2 -1
  315. data/lib/graphql/tracing/active_support_notifications_trace.rb +1 -0
  316. data/lib/graphql/tracing/active_support_notifications_tracing.rb +1 -0
  317. data/lib/graphql/tracing/appoptics_trace.rb +1 -0
  318. data/lib/graphql/tracing/appoptics_tracing.rb +1 -0
  319. data/lib/graphql/tracing/appsignal_trace.rb +1 -0
  320. data/lib/graphql/tracing/appsignal_tracing.rb +1 -0
  321. data/lib/graphql/tracing/call_legacy_tracers.rb +1 -0
  322. data/lib/graphql/tracing/data_dog_trace.rb +1 -0
  323. data/lib/graphql/tracing/data_dog_tracing.rb +1 -0
  324. data/lib/graphql/tracing/detailed_trace/active_record_backend.rb +1 -0
  325. data/lib/graphql/tracing/detailed_trace/memory_backend.rb +1 -0
  326. data/lib/graphql/tracing/detailed_trace/redis_backend.rb +1 -0
  327. data/lib/graphql/tracing/detailed_trace.rb +1 -0
  328. data/lib/graphql/tracing/legacy_hooks_trace.rb +1 -0
  329. data/lib/graphql/tracing/legacy_trace.rb +2 -1
  330. data/lib/graphql/tracing/monitor_trace.rb +1 -0
  331. data/lib/graphql/tracing/new_relic_trace.rb +1 -0
  332. data/lib/graphql/tracing/new_relic_tracing.rb +1 -0
  333. data/lib/graphql/tracing/notifications_trace.rb +1 -0
  334. data/lib/graphql/tracing/notifications_tracing.rb +1 -0
  335. data/lib/graphql/tracing/null_trace.rb +2 -1
  336. data/lib/graphql/tracing/perfetto_trace/trace_pb.rb +1 -0
  337. data/lib/graphql/tracing/perfetto_trace.rb +1 -0
  338. data/lib/graphql/tracing/platform_trace.rb +1 -0
  339. data/lib/graphql/tracing/platform_tracing.rb +1 -0
  340. data/lib/graphql/tracing/prometheus_trace/graphql_collector.rb +1 -0
  341. data/lib/graphql/tracing/prometheus_trace.rb +1 -0
  342. data/lib/graphql/tracing/prometheus_tracing.rb +1 -0
  343. data/lib/graphql/tracing/scout_trace.rb +1 -0
  344. data/lib/graphql/tracing/scout_tracing.rb +1 -0
  345. data/lib/graphql/tracing/sentry_trace.rb +1 -0
  346. data/lib/graphql/tracing/statsd_trace.rb +1 -0
  347. data/lib/graphql/tracing/statsd_tracing.rb +1 -0
  348. data/lib/graphql/tracing/trace.rb +1 -0
  349. data/lib/graphql/tracing.rb +1 -0
  350. data/lib/graphql/type_kinds.rb +1 -0
  351. data/lib/graphql/types/big_int.rb +5 -1
  352. data/lib/graphql/types/boolean.rb +4 -1
  353. data/lib/graphql/types/float.rb +4 -1
  354. data/lib/graphql/types/id.rb +4 -1
  355. data/lib/graphql/types/int.rb +6 -3
  356. data/lib/graphql/types/iso_8601_date.rb +4 -1
  357. data/lib/graphql/types/iso_8601_date_time.rb +7 -2
  358. data/lib/graphql/types/iso_8601_duration.rb +7 -2
  359. data/lib/graphql/types/json.rb +4 -1
  360. data/lib/graphql/types/relay/base_connection.rb +2 -1
  361. data/lib/graphql/types/relay/base_edge.rb +2 -1
  362. data/lib/graphql/types/relay/connection_behaviors.rb +1 -2
  363. data/lib/graphql/types/relay/edge_behaviors.rb +1 -2
  364. data/lib/graphql/types/relay/has_node_field.rb +7 -1
  365. data/lib/graphql/types/relay/has_nodes_field.rb +7 -1
  366. data/lib/graphql/types/relay/node.rb +2 -1
  367. data/lib/graphql/types/relay/node_behaviors.rb +7 -1
  368. data/lib/graphql/types/relay/page_info.rb +2 -1
  369. data/lib/graphql/types/relay/page_info_behaviors.rb +5 -1
  370. data/lib/graphql/types/relay.rb +2 -1
  371. data/lib/graphql/types/string.rb +4 -1
  372. data/lib/graphql/types.rb +2 -1
  373. data/lib/graphql/unauthorized_enum_value_error.rb +1 -0
  374. data/lib/graphql/unauthorized_error.rb +1 -0
  375. data/lib/graphql/unauthorized_field_error.rb +1 -0
  376. data/lib/graphql/unresolved_type_error.rb +1 -0
  377. data/lib/graphql/version.rb +3 -2
  378. data/lib/graphql.rb +1 -0
  379. metadata +3 -4
  380. data/lib/graphql/query/variables.rb +0 -99
  381. data/lib/graphql/static_validation/literal_validator.rb +0 -157
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  require "graphql/execution/interpreter/runtime/graphql_result"
4
5
 
@@ -220,8 +221,9 @@ module GraphQL
220
221
  end
221
222
  end
222
223
 
223
- #: (untyped, untyped, untyped, untyped, Array[untyped]?, untyped, untyped) -> untyped
224
- def gather_selections(graphql_response, owner_object, owner_type, selections, selections_to_run, selections_by_name, ordered_result_keys)
224
+ #: (untyped, untyped, untyped, untyped, Array[untyped]?, untyped, untyped, ?inlined_fragments: Hash[untyped, Hash[String, bool]]?) -> untyped
225
+ def gather_selections(graphql_response, owner_object, owner_type, selections, selections_to_run, selections_by_name, ordered_result_keys, inlined_fragments: nil)
226
+ inlined_fragments = inlined_fragments #: Hash[untyped, Hash[String, bool]]?
225
227
  selections.each do |node|
226
228
  if node.is_a?(GraphQL::Language::Nodes::Field)
227
229
  response_key = node.alias || node.name
@@ -271,14 +273,14 @@ module GraphQL
271
273
  )
272
274
 
273
275
  if query.types.possible_types(type_defn).include?(owner_type)
274
- result = gather_selections(graphql_response, owner_object, owner_type, node.selections, selections_to_run, next_selections, ordered_result_keys)
276
+ result = gather_selections(graphql_response, owner_object, owner_type, node.selections, selections_to_run, next_selections, ordered_result_keys, inlined_fragments: inlined_fragments)
275
277
  if !result.equal?(next_selections)
276
278
  selections_to_run = result
277
279
  end
278
280
  end
279
281
  else
280
282
  # it's an untyped fragment, definitely continue
281
- result = gather_selections(graphql_response, owner_object, owner_type, node.selections, selections_to_run, next_selections, ordered_result_keys)
283
+ result = gather_selections(graphql_response, owner_object, owner_type, node.selections, selections_to_run, next_selections, ordered_result_keys, inlined_fragments: inlined_fragments)
282
284
  if !result.equal?(next_selections)
283
285
  selections_to_run = result
284
286
  end
@@ -286,8 +288,12 @@ module GraphQL
286
288
  when GraphQL::Language::Nodes::FragmentSpread
287
289
  fragment_def = query.fragments[node.name]
288
290
  type_defn = query.types.type(fragment_def.type.name)
289
- if query.types.possible_types(type_defn).include?(owner_type)
290
- result = gather_selections(graphql_response, owner_object, owner_type, fragment_def.selections, selections_to_run, next_selections, ordered_result_keys)
291
+ # Spreading the same fragment again into these selections adds nothing, so only gather it once.
292
+ inlined_fragments ||= {}.compare_by_identity
293
+ inlined_names = (inlined_fragments[next_selections] ||= {})
294
+ if !inlined_names.key?(node.name) && query.types.possible_types(type_defn).include?(owner_type)
295
+ inlined_names[node.name] = true
296
+ result = gather_selections(graphql_response, owner_object, owner_type, fragment_def.selections, selections_to_run, next_selections, ordered_result_keys, inlined_fragments: inlined_fragments)
291
297
  if !result.equal?(next_selections)
292
298
  selections_to_run = result
293
299
  end
@@ -504,14 +510,14 @@ module GraphQL
504
510
  end
505
511
  @current_trace.end_execute_field(field_defn, object, kwarg_arguments, query, app_result)
506
512
  after_lazy(app_result, field: field_defn, ast_node: ast_node, owner_object: object, arguments: resolved_arguments, result_name: result_name, result: selection_result, runtime_state: runtime_state) do |inner_result, runtime_state|
513
+ was_scoped = runtime_state.was_authorized_by_scope_items
514
+ runtime_state.was_authorized_by_scope_items = nil
507
515
  next if selection_result.collect_result(result_name, inner_result)
508
516
 
509
517
  owner_type = selection_result.graphql_result_type
510
518
  return_type = field_defn.type
511
519
  continue_value = continue_value(inner_result, field_defn, return_type.non_null?, ast_node, result_name, selection_result)
512
520
  if HALT != continue_value
513
- was_scoped = runtime_state.was_authorized_by_scope_items
514
- runtime_state.was_authorized_by_scope_items = nil
515
521
  continue_field(continue_value, owner_type, field_defn, return_type, ast_node, next_selections, false, object, resolved_arguments, result_name, selection_result, was_scoped, runtime_state)
516
522
  else
517
523
  nil
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ #--
3
+ # typed: strict
3
4
  require "fiber"
4
5
  require "graphql/execution/interpreter/argument_value"
5
6
  require "graphql/execution/interpreter/arguments"
@@ -30,6 +31,7 @@ module GraphQL
30
31
  #
31
32
  # :call-seq:
32
33
  # run_all(GraphQL::Schema schema, query_options, Hash context:, Integer | nil max_complexity:) -> Array[GraphQL::Query::Result]
34
+ #: (singleton(GraphQL::Schema) schema, Array[untyped] query_options, ?context: Hash[Symbol, untyped], ?max_complexity: Integer?) -> Array[GraphQL::Query::Result]
33
35
  def run_all(schema, query_options, context: {}, max_complexity: schema.max_complexity)
34
36
  previous_multiplex = Fiber[:__graphql_current_multiplex]
35
37
  queries = query_options.map do |opts|
@@ -42,7 +44,7 @@ module GraphQL
42
44
  raise "Expected Hash or GraphQL::Query, not #{opts.class} (#{opts.inspect})"
43
45
  end
44
46
  query
45
- end
47
+ end #: Array[untyped]
46
48
 
47
49
  return GraphQL::EmptyObjects::EMPTY_ARRAY if queries.empty?
48
50
 
@@ -50,8 +52,8 @@ module GraphQL
50
52
  trace = multiplex.current_trace
51
53
  Fiber[:__graphql_current_multiplex] = multiplex
52
54
  trace.execute_multiplex(multiplex: multiplex) do
53
- schema = multiplex.schema
54
- queries = multiplex.queries
55
+ schema = multiplex.schema #: singleton(GraphQL::Schema)
56
+ queries = multiplex.queries #: Array[untyped]
55
57
  multiplex_analyzers = schema.multiplex_analyzers
56
58
  if multiplex.max_complexity
57
59
  multiplex_analyzers += [GraphQL::Analysis::MaxQueryComplexity]
@@ -155,6 +157,7 @@ module GraphQL
155
157
  end
156
158
 
157
159
  class ListResultFailedError < GraphQL::Error
160
+ #: (value: untyped, path: Array[String | Integer], field: GraphQL::Schema::Field) -> void
158
161
  def initialize(value:, path:, field:)
159
162
  message = "Failed to build a GraphQL list result for field `#{field.path}` at path `#{path.join(".")}`.\n".dup
160
163
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  require 'thread'
4
5
  begin
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  require "graphql/execution/lazy/lazy_method_map"
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  module GraphQL
4
5
  module Execution
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  module GraphQL
4
5
  module Execution
@@ -344,7 +345,8 @@ module GraphQL
344
345
  false
345
346
  end
346
347
 
347
- def find_selections(subselections_by_type, selections_on_type, selected_type, ast_selections, arguments)
348
+ def find_selections(subselections_by_type, selections_on_type, selected_type, ast_selections, arguments, inlined_fragments: nil)
349
+ inlined_fragments = inlined_fragments #: Hash[untyped, Hash[String, bool]]?
348
350
  ast_selections.each do |ast_selection|
349
351
  next if skipped_by_directive?(ast_selection)
350
352
 
@@ -369,13 +371,19 @@ module GraphQL
369
371
  on_type = @query.types.type(t.name)
370
372
  subselections_on_type = subselections_by_type[on_type] ||= {}
371
373
  end
372
- find_selections(subselections_by_type, subselections_on_type, on_type, ast_selection.selections, arguments)
374
+ find_selections(subselections_by_type, subselections_on_type, on_type, ast_selection.selections, arguments, inlined_fragments: inlined_fragments)
373
375
  when GraphQL::Language::Nodes::FragmentSpread
374
376
  frag_defn = lookup_fragment(ast_selection)
375
377
  # Again, assuming a valid AST
376
378
  on_type = @query.types.type(frag_defn.type.name)
377
379
  subselections_on_type = subselections_by_type[on_type] ||= {}
378
- find_selections(subselections_by_type, subselections_on_type, on_type, frag_defn.selections, arguments)
380
+ # Spreading the same fragment again into these selections adds nothing, so only find its selections once.
381
+ inlined_fragments ||= {}.compare_by_identity
382
+ inlined_names = (inlined_fragments[subselections_on_type] ||= {})
383
+ if !inlined_names.key?(ast_selection.name)
384
+ inlined_names[ast_selection.name] = true
385
+ find_selections(subselections_by_type, subselections_on_type, on_type, frag_defn.selections, arguments, inlined_fragments: inlined_fragments)
386
+ end
379
387
  else
380
388
  raise "Invariant: Unexpected selection type: #{ast_selection.class}"
381
389
  end
@@ -384,7 +392,7 @@ module GraphQL
384
392
 
385
393
  # If a selection on `node` matches `field_name` (which is backed by `field_defn`)
386
394
  # and matches the `arguments:` constraints, then add that node to `matches`
387
- def find_selected_nodes(node, field_name, field_defn, arguments:, matches:, alias_name: NOT_CONFIGURED)
395
+ def find_selected_nodes(node, field_name, field_defn, arguments:, matches:, alias_name: NOT_CONFIGURED, inlined_fragments: nil)
388
396
  return if skipped_by_directive?(node)
389
397
  case node
390
398
  when GraphQL::Language::Nodes::Field
@@ -397,10 +405,14 @@ module GraphQL
397
405
  end
398
406
  end
399
407
  when GraphQL::Language::Nodes::InlineFragment
400
- node.selections.each { |s| find_selected_nodes(s, field_name, field_defn, arguments: arguments, matches: matches, alias_name: alias_name) }
408
+ node.selections.each { |s| find_selected_nodes(s, field_name, field_defn, arguments: arguments, matches: matches, alias_name: alias_name, inlined_fragments: inlined_fragments) }
401
409
  when GraphQL::Language::Nodes::FragmentSpread
402
- frag_defn = lookup_fragment(node)
403
- frag_defn.selections.each { |s| find_selected_nodes(s, field_name, field_defn, arguments: arguments, matches: matches, alias_name: alias_name) }
410
+ # A fragment spread again would only add the same nodes, so only search it once.
411
+ if inlined_fragments.nil? || !inlined_fragments.key?(node.name)
412
+ (inlined_fragments ||= {})[node.name] = true
413
+ frag_defn = lookup_fragment(node)
414
+ frag_defn.selections.each { |s| find_selected_nodes(s, field_name, field_defn, arguments: arguments, matches: matches, alias_name: alias_name, inlined_fragments: inlined_fragments) }
415
+ end
404
416
  else
405
417
  raise "Unexpected selection comparison on #{node.class.name} (#{node})"
406
418
  end
@@ -425,9 +437,10 @@ module GraphQL
425
437
 
426
438
  next_nodes = []
427
439
  field_name = field_defn.name
440
+ inlined_fragments = {}
428
441
  @ast_nodes.each do |ast_node|
429
442
  ast_node.selections.each do |selection|
430
- find_selected_nodes(selection, field_name, field_defn, arguments: arguments, matches: next_nodes, alias_name: alias_name)
443
+ find_selected_nodes(selection, field_name, field_defn, arguments: arguments, matches: next_nodes, alias_name: alias_name, inlined_fragments: inlined_fragments)
431
444
  end
432
445
  end
433
446
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  module GraphQL
4
5
  module Execution
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  require "graphql/execution/prepare_object_step"
4
5
  require "graphql/execution/input_values"
6
+ require "graphql/execution/variable_values"
5
7
  require "graphql/execution/field_resolve_step"
6
8
  require "graphql/execution/finalize"
7
9
  require "graphql/execution/load_argument_step"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  module GraphQL
4
5
  module Execution
@@ -130,11 +131,8 @@ module GraphQL
130
131
  @graphql_result[@key] = add_field_error(@authorization_error)
131
132
  end
132
133
  rescue GraphQL::RuntimeError => err
133
- if @is_non_null
134
- @graphql_result[@key] = @field_resolve_step.add_non_null_error(@is_from_array)
135
- else
136
- @graphql_result[@key] = add_field_error(err)
137
- end
134
+ # Like the classic runtime, report the raised error itself; add_graphql_error propagates the null for non-null types.
135
+ @graphql_result[@key] = add_field_error(err)
138
136
  end
139
137
  end
140
138
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  module GraphQL
4
5
  module Execution
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  module GraphQL
4
5
  module Execution
@@ -12,9 +13,6 @@ module GraphQL
12
13
  @selected_operation = nil
13
14
  @dataloader = multiplex.context[:dataloader] ||= @schema.dataloader_class.new
14
15
  @resolves_lazies = @schema.resolves_lazies?
15
- @input_values = Hash.new do |h, query|
16
- h[query] = InputValues.new(query, self)
17
- end.compare_by_identity
18
16
 
19
17
  @runtime_directives = nil #: Hash[String, singleton(GraphQL::Schema::Directive)]?
20
18
  @schema.directives.each do |name, dir_class|
@@ -53,7 +51,7 @@ module GraphQL
53
51
  @dataloader.append_job(step)
54
52
  end
55
53
 
56
- attr_reader :schema, :variables, :dataloader, :resolves_lazies, :authorizes, :static_type_at, :runtime_type_at, :finalizers, :input_values
54
+ attr_reader :schema, :variables, :dataloader, :resolves_lazies, :authorizes, :static_type_at, :runtime_type_at, :finalizers
57
55
 
58
56
  # **Returns**
59
57
  #
@@ -95,11 +93,15 @@ module GraphQL
95
93
 
96
94
  results = {}.compare_by_identity
97
95
  queries.each do |query|
98
- if query.validate && !query.valid?
96
+ # `valid?` also covers variable, operation name and analysis errors, which apply even with `validate: false`.
97
+ if !query.valid? || !query.context.errors.empty?
99
98
  results[query] = {
100
99
  "errors" => query.static_errors.map(&:to_h)
101
100
  }
102
101
  next
102
+ elsif query.selected_operation.nil?
103
+ results[query] = {}
104
+ next
103
105
  end
104
106
 
105
107
  root_type = query.root_type
@@ -176,7 +178,8 @@ module GraphQL
176
178
  Fiber[:__graphql_current_multiplex] = previous_multiplex
177
179
  end
178
180
 
179
- def gather_selections(type_defn, ast_selections, selections_step, query, all_selections, prototype_result, into:)
181
+ def gather_selections(type_defn, ast_selections, selections_step, query, all_selections, prototype_result, into:, inlined_fragments: nil)
182
+ inlined_fragments = inlined_fragments #: Hash[untyped, Hash[String, bool]]?
180
183
  ast_selections.each do |ast_selection|
181
184
  next if !directives_include?(query, ast_selection)
182
185
 
@@ -201,7 +204,7 @@ module GraphQL
201
204
  all_selections << (into = { __node: ast_selection })
202
205
  all_selections << (prototype_result = {})
203
206
  end
204
- gather_selections(type_defn, ast_selection.selections, selections_step, query, all_selections, prototype_result, into: into)
207
+ gather_selections(type_defn, ast_selection.selections, selections_step, query, all_selections, prototype_result, into: into, inlined_fragments: inlined_fragments)
205
208
  end
206
209
  when GraphQL::Language::Nodes::FragmentSpread
207
210
  fragment_definition = query.fragments[ast_selection.name]
@@ -211,7 +214,13 @@ module GraphQL
211
214
  all_selections << (into = { __node: ast_selection })
212
215
  all_selections << (prototype_result = {})
213
216
  end
214
- gather_selections(type_defn, fragment_definition.selections, selections_step, query, all_selections, prototype_result, into: into)
217
+ # Spreading the same fragment again into these selections adds nothing, so only gather it once.
218
+ inlined_fragments ||= {}.compare_by_identity
219
+ inlined_names = (inlined_fragments[into] ||= {})
220
+ if !inlined_names.key?(ast_selection.name)
221
+ inlined_names[ast_selection.name] = true
222
+ gather_selections(type_defn, fragment_definition.selections, selections_step, query, all_selections, prototype_result, into: into, inlined_fragments: inlined_fragments)
223
+ end
215
224
  end
216
225
  else
217
226
  raise ArgumentError, "Unsupported graphql selection node: #{ast_selection.class} (#{ast_selection.inspect})"
@@ -285,7 +294,7 @@ module GraphQL
285
294
  continue_execution = true #: bool
286
295
  query_dirs.each do |dir_node|
287
296
  dir_defn = runtime_directives[dir_node.name] || raise(GraphQL::Error, "No directive definition found for: #{dir_node.name.inspect}")
288
- dir_args, errors = input_values[query].argument_values(dir_defn, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
297
+ dir_args, errors = query.input_values.argument_values(dir_defn, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
289
298
  if errors
290
299
  errors.each { |e|
291
300
  e.ast_node = dir_node
@@ -412,14 +421,14 @@ module GraphQL
412
421
  if ast_selection.directives.any? { |dir_node|
413
422
  case dir_node.name
414
423
  when "skip"
415
- skip_args, _errors = @input_values[query].argument_values(GraphQL::Schema::Directive::Skip, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
424
+ skip_args, _errors = query.input_values.argument_values(GraphQL::Schema::Directive::Skip, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
416
425
  skip_args[:if] == true
417
426
  when "include"
418
- include_args, _errors = @input_values[query].argument_values(GraphQL::Schema::Directive::Include, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
427
+ include_args, _errors = query.input_values.argument_values(GraphQL::Schema::Directive::Include, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
419
428
  include_args[:if] == false
420
429
  else
421
430
  dir_defn = runtime_directives[dir_node.name]
422
- dir_args, _errors = @input_values[query].argument_values(dir_defn, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
431
+ dir_args, _errors = query.input_values.argument_values(dir_defn, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
423
432
  !dir_defn.include?(nil, dir_args, query.context)
424
433
  end
425
434
  }
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  module GraphQL
4
5
  module Execution
@@ -43,7 +44,7 @@ module GraphQL
43
44
  directives.each do |dir_node|
44
45
  dir_defn = @runner.runtime_directives[dir_node.name]
45
46
  if dir_defn # not present for `skip` or `include`
46
- dir_args, _errors = @runner.input_values[query].argument_values(dir_defn, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
47
+ dir_args, _errors = query.input_values.argument_values(dir_defn, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
47
48
  result = case directives_owner
48
49
  when Language::Nodes::FragmentSpread
49
50
  dir_defn.resolve_fragment_spread(directives_owner, @parent_type, @objects, dir_args, self.query.context)
@@ -0,0 +1,262 @@
1
+ # frozen_string_literal: true
2
+ #--
3
+ # typed: true
4
+ module GraphQL
5
+ module Execution
6
+ # Validates and coerces a query's provided variables in a single pass.
7
+ #
8
+ # Reading methods (`#[]`, `#fetch`, `#to_h`, ...) return the values _as provided_ by the client
9
+ # (or the default value from the query string), so that existing callers keep working.
10
+ # Coerced values are available from `#coerced_value` for the runtime.
11
+ class VariableValues
12
+ extend Forwardable
13
+
14
+ # **Returns**
15
+ #
16
+ # - `Array<GraphQL::Query::VariableValidationError>` — Any errors encountered when coercing the provided variables
17
+ attr_reader :errors
18
+
19
+ attr_reader :context
20
+
21
+ def initialize(query, ast_variables, provided_variables)
22
+ @query = query
23
+ @context = query.context
24
+ @types = query.types
25
+ @schema = query.schema
26
+ @provided_variables = deep_stringify(provided_variables)
27
+ @errors = []
28
+ @storage = {}
29
+ @coerced_values = {}
30
+ build_values(ast_variables)
31
+ end
32
+
33
+ def_delegators :@storage, :length, :key?, :[], :fetch, :to_h, :each
34
+
35
+ # **Returns**
36
+ #
37
+ # - `Object` — The coerced value for the variable named `name`, or `nil` if it wasn't given
38
+ def coerced_value(name) # :nodoc:
39
+ @coerced_values[name]
40
+ end
41
+
42
+ private
43
+
44
+ UNEXPECTED_NULL_MESSAGE = "Expected value to not be null"
45
+ INVALID_OBJECT_MESSAGE = "Expected %{object} to be a key-value object."
46
+
47
+ def build_values(ast_variables)
48
+ max_errors = @schema.validate_max_errors
49
+ ast_variables.each do |ast_variable|
50
+ if max_errors && max_errors <= @errors.size
51
+ add_max_errors_reached_message
52
+ break
53
+ end
54
+ variable_type = GraphQL::Schema::TypeExpression.build_type(@types, ast_variable.type)
55
+ if variable_type.nil? || !variable_type.unwrap.kind.input?
56
+ # Pass -- it will get handled by a validator
57
+ next
58
+ end
59
+
60
+ variable_name = ast_variable.name
61
+ default_value = ast_variable.default_value
62
+ value_was_provided = @provided_variables.key?(variable_name)
63
+
64
+ if value_was_provided || default_value.nil?
65
+ provided_value = @provided_variables[variable_name]
66
+ validation_result = GraphQL::Query::InputValidationResult.new
67
+ remaining_errors = max_errors ? max_errors - @errors.size : nil
68
+ path = []
69
+ coerced_value = begin
70
+ coerce_variable_value(provided_value, variable_type, path, validation_result, remaining_errors)
71
+ rescue GraphQL::ExecutionError => ex
72
+ # TODO: This should really include the path to the problematic node in the variable value
73
+ validation_result = GraphQL::Query::InputValidationResult.from_problem(ex.message)
74
+ nil
75
+ end
76
+ if !validation_result.valid?
77
+ @errors << GraphQL::Query::VariableValidationError.new(ast_variable, variable_type, provided_value, validation_result)
78
+ elsif value_was_provided
79
+ @storage[variable_name] = provided_value
80
+ @coerced_values[variable_name] = coerced_value
81
+ end
82
+ elsif default_value.is_a?(Language::Nodes::NullValue)
83
+ @storage[variable_name] = nil
84
+ @coerced_values[variable_name] = nil
85
+ else
86
+ @storage[variable_name] = default_value
87
+ @coerced_values[variable_name] = @query.input_values.value_from_ast(default_value, variable_type)
88
+ end
89
+ end
90
+ end
91
+
92
+ def coerce_variable_value(value, type, path, result, max_errors)
93
+ if type.non_null?
94
+ if value.nil?
95
+ result.add_problem(UNEXPECTED_NULL_MESSAGE, path.dup)
96
+ return nil
97
+ end
98
+ type = type.of_type
99
+ end
100
+
101
+ if value.nil?
102
+ nil
103
+ elsif type.list?
104
+ coerce_list_value(value, type.of_type, path, result, max_errors)
105
+ elsif type.kind.input_object?
106
+ coerce_input_object_value(value, type, path, result)
107
+ elsif type.kind.enum?
108
+ coerce_enum_value(value, type, path, result)
109
+ elsif type.kind.scalar?
110
+ coerce_scalar_value(value, type, path, result)
111
+ else
112
+ raise GraphQL::Error, "Unexpected input type: #{type.graphql_name}."
113
+ end
114
+ end
115
+
116
+ def coerce_list_value(value, item_type, path, result, max_errors)
117
+ items = value.is_a?(Array) ? value : [value]
118
+ coerced_items = Array.new(items.size)
119
+ invalid_items = 0
120
+ items.each_with_index do |item, idx|
121
+ item_result = GraphQL::Query::InputValidationResult.new
122
+ path.push(idx)
123
+ coerced_items[idx] = coerce_variable_value(item, item_type, path, item_result, nil)
124
+ path.pop
125
+ if !item_result.valid?
126
+ if max_errors
127
+ if invalid_items == max_errors
128
+ result.add_problem("Too many errors processing list variable, max validation error limit reached. Execution aborted", [*path, nil])
129
+ break
130
+ end
131
+ invalid_items += 1
132
+ end
133
+ item_result.problems.each do |problem|
134
+ result.add_problem(problem["explanation"], problem["path"], message: problem["message"], extensions: problem["extensions"])
135
+ end
136
+ end
137
+ end
138
+ coerced_items.freeze
139
+ end
140
+
141
+ def coerce_input_object_value(value, type, path, result)
142
+ if value.is_a?(Array) || !(value.respond_to?(:to_h) || value.respond_to?(:to_unsafe_h))
143
+ result.add_problem(INVALID_OBJECT_MESSAGE % { object: JSON.generate(value) }, path.dup)
144
+ return nil
145
+ end
146
+
147
+ coerced_obj = {}
148
+ value.each do |argument_name, argument_value|
149
+ path.push(argument_name)
150
+ argument = @types.argument(type, argument_name)
151
+ if argument.nil?
152
+ result.add_problem("Field is not defined on #{type.graphql_name}", path.dup)
153
+ else
154
+ if argument_value.nil? && argument.replace_null_with_default?
155
+ coerced_obj[argument.keyword] = argument.default_value
156
+ else
157
+ coerced_obj[argument.keyword] = coerce_variable_value(argument_value, argument.type, path, result, nil)
158
+ end
159
+ end
160
+ path.pop
161
+ end
162
+
163
+ @types.arguments(type).each do |argument|
164
+ if !value.key?(argument.graphql_name)
165
+ if argument.default_value?
166
+ coerced_obj[argument.keyword] = argument.default_value
167
+ elsif argument.type.non_null?
168
+ path.push(argument.graphql_name)
169
+ result.add_problem(UNEXPECTED_NULL_MESSAGE, path.dup)
170
+ path.pop
171
+ end
172
+ end
173
+ end
174
+
175
+ if type.one_of?
176
+ if value.size == 1
177
+ value.each do |name, v|
178
+ if v.nil?
179
+ result.add_problem("'#{type.graphql_name}' requires exactly one argument, but '#{name}' was `null`.", path.dup)
180
+ end
181
+ end
182
+ else
183
+ result.add_problem("'#{type.graphql_name}' requires exactly one argument, but #{value.size} were provided.", path.dup)
184
+ end
185
+ end
186
+
187
+ coerced_obj
188
+ end
189
+
190
+ def coerce_enum_value(value, type, path, result)
191
+ allowed_values = @types.enum_values(type)
192
+ matching_value = allowed_values.find { |v| v.graphql_name == value }
193
+ if matching_value.nil?
194
+ result.add_problem("Expected #{GraphQL::Language.serialize(value)} to be one of: #{allowed_values.map(&:graphql_name).join(', ')}", path.dup)
195
+ nil
196
+ else
197
+ begin
198
+ type.coerce_input(value, @context)
199
+ rescue GraphQL::UnauthorizedEnumValueError => enum_err
200
+ @schema.unauthorized_object(enum_err)
201
+ end
202
+ end
203
+ rescue GraphQL::ExecutionError => err
204
+ result.add_problem(err.message, path.dup)
205
+ nil
206
+ end
207
+
208
+ def coerce_scalar_value(value, type, path, result)
209
+ scalar_result = begin
210
+ type.validate_non_null_input(value, @context)
211
+ rescue GraphQL::CoercionError => err
212
+ result.add_problem(err.message, path.dup, message: err.message, extensions: err.extensions)
213
+ return nil
214
+ rescue GraphQL::ExecutionError => err
215
+ result.add_problem(err.message, path.dup)
216
+ return nil
217
+ rescue StandardError => err
218
+ return @query.handle_or_reraise(err)
219
+ end
220
+
221
+ if scalar_result && !scalar_result.valid?
222
+ problems = scalar_result.problems
223
+ if problems.nil? || problems.empty?
224
+ result.add_problem("Could not coerce value #{GraphQL::Language.serialize(value)} to #{type.graphql_name}", path.dup)
225
+ else
226
+ problems.each do |problem|
227
+ result.add_problem(problem["explanation"], [*path, *problem["path"]], message: problem["message"], extensions: problem["extensions"])
228
+ end
229
+ end
230
+ nil
231
+ elsif scalar_result&.coerced_value?
232
+ scalar_result.coerced_value
233
+ else
234
+ # A custom `validate_non_null_input` accepted this value but didn't provide a coerced value.
235
+ # Call `coerce_input` at runtime, like GraphQL-Ruby did before 2.6.15.
236
+ GraphQL::Execution::InputValues::DeferredCoercion.new(type, value)
237
+ end
238
+ end
239
+
240
+ def add_max_errors_reached_message
241
+ message = "Too many errors processing variables, max validation error limit reached. Execution aborted"
242
+ validation_result = GraphQL::Query::InputValidationResult.from_problem(message)
243
+ @errors << GraphQL::Query::VariableValidationError.new(nil, nil, nil, validation_result, msg: message)
244
+ end
245
+
246
+ def deep_stringify(val)
247
+ case val
248
+ when Array
249
+ val.map { |v| deep_stringify(v) }
250
+ when Hash
251
+ new_val = {}
252
+ val.each do |k, v|
253
+ new_val[k.to_s] = deep_stringify(v)
254
+ end
255
+ new_val
256
+ else
257
+ val
258
+ end
259
+ end
260
+ end
261
+ end
262
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  require "graphql/execution/directive_checks"
4
5
  require "graphql/execution/next"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ #--
2
3
  # typed: true
3
4
  module GraphQL
4
5
  # If a field's resolve function returns an [ExecutionError](rdoc-ref:GraphQL::ExecutionError),
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
2
+ #--
3
+ # typed: strict
3
4
  module GraphQL
4
5
  # This error is raised when `Types::Float` is given a non-finite input value.
5
6
  class FloatDecodingError < GraphQL::RuntimeTypeError
6
7
  # The value which couldn't be decoded
8
+ #: Float
7
9
  attr_reader :float_value
8
10
 
11
+ #: (Float value) -> void
9
12
  def initialize(value)
10
13
  @float_value = value
11
14
  super("Float is not finite: #{value.inspect}.")