graphql 1.9.11 → 1.9.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (286) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/analysis/ast/query_complexity.rb +0 -8
  3. data/lib/graphql/analysis/ast/query_depth.rb +0 -8
  4. data/lib/graphql/analysis/ast/visitor.rb +26 -24
  5. data/lib/graphql/execution.rb +1 -0
  6. data/lib/graphql/execution/errors.rb +60 -0
  7. data/lib/graphql/execution/interpreter/runtime.rb +21 -17
  8. data/lib/graphql/static_validation/rules/fields_will_merge.rb +15 -8
  9. data/lib/graphql/version.rb +1 -1
  10. metadata +5 -556
  11. data/spec/dummy/Gemfile +0 -12
  12. data/spec/dummy/README.md +0 -24
  13. data/spec/dummy/Rakefile +0 -7
  14. data/spec/dummy/app/assets/config/manifest.js +0 -1
  15. data/spec/dummy/app/assets/javascripts/application.js +0 -66
  16. data/spec/dummy/app/channels/application_cable/channel.rb +0 -5
  17. data/spec/dummy/app/channels/application_cable/connection.rb +0 -5
  18. data/spec/dummy/app/channels/graphql_channel.rb +0 -116
  19. data/spec/dummy/app/controllers/application_controller.rb +0 -4
  20. data/spec/dummy/app/controllers/pages_controller.rb +0 -5
  21. data/spec/dummy/app/helpers/application_helper.rb +0 -3
  22. data/spec/dummy/app/jobs/application_job.rb +0 -3
  23. data/spec/dummy/app/views/layouts/application.html.erb +0 -12
  24. data/spec/dummy/app/views/pages/show.html +0 -16
  25. data/spec/dummy/bin/bundle +0 -4
  26. data/spec/dummy/bin/rails +0 -5
  27. data/spec/dummy/bin/rake +0 -5
  28. data/spec/dummy/bin/setup +0 -31
  29. data/spec/dummy/bin/update +0 -27
  30. data/spec/dummy/bin/yarn +0 -12
  31. data/spec/dummy/config.ru +0 -6
  32. data/spec/dummy/config/application.rb +0 -30
  33. data/spec/dummy/config/boot.rb +0 -4
  34. data/spec/dummy/config/cable.yml +0 -10
  35. data/spec/dummy/config/environment.rb +0 -6
  36. data/spec/dummy/config/environments/development.rb +0 -40
  37. data/spec/dummy/config/environments/production.rb +0 -76
  38. data/spec/dummy/config/environments/test.rb +0 -37
  39. data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -9
  40. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -8
  41. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -6
  42. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -5
  43. data/spec/dummy/config/initializers/inflections.rb +0 -17
  44. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  45. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -10
  46. data/spec/dummy/config/locales/en.yml +0 -33
  47. data/spec/dummy/config/puma.rb +0 -57
  48. data/spec/dummy/config/routes.rb +0 -4
  49. data/spec/dummy/config/secrets.yml +0 -32
  50. data/spec/dummy/package.json +0 -5
  51. data/spec/dummy/public/404.html +0 -67
  52. data/spec/dummy/public/422.html +0 -67
  53. data/spec/dummy/public/500.html +0 -66
  54. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  55. data/spec/dummy/public/apple-touch-icon.png +0 -0
  56. data/spec/dummy/public/favicon.ico +0 -0
  57. data/spec/dummy/public/robots.txt +0 -1
  58. data/spec/dummy/test/application_system_test_case.rb +0 -6
  59. data/spec/dummy/test/system/action_cable_subscription_test.rb +0 -45
  60. data/spec/dummy/test/test_helper.rb +0 -4
  61. data/spec/fixtures/upgrader/account.original.rb +0 -19
  62. data/spec/fixtures/upgrader/account.transformed.rb +0 -20
  63. data/spec/fixtures/upgrader/blame_range.original.rb +0 -43
  64. data/spec/fixtures/upgrader/blame_range.transformed.rb +0 -30
  65. data/spec/fixtures/upgrader/date_time.original.rb +0 -24
  66. data/spec/fixtures/upgrader/date_time.transformed.rb +0 -23
  67. data/spec/fixtures/upgrader/delete_project.original.rb +0 -28
  68. data/spec/fixtures/upgrader/delete_project.transformed.rb +0 -27
  69. data/spec/fixtures/upgrader/gist_order_field.original.rb +0 -14
  70. data/spec/fixtures/upgrader/gist_order_field.transformed.rb +0 -13
  71. data/spec/fixtures/upgrader/increment_count.original.rb +0 -59
  72. data/spec/fixtures/upgrader/increment_count.transformed.rb +0 -50
  73. data/spec/fixtures/upgrader/mutation.original.rb +0 -28
  74. data/spec/fixtures/upgrader/mutation.transformed.rb +0 -28
  75. data/spec/fixtures/upgrader/photo.original.rb +0 -10
  76. data/spec/fixtures/upgrader/photo.transformed.rb +0 -12
  77. data/spec/fixtures/upgrader/release_order.original.rb +0 -15
  78. data/spec/fixtures/upgrader/release_order.transformed.rb +0 -14
  79. data/spec/fixtures/upgrader/starrable.original.rb +0 -49
  80. data/spec/fixtures/upgrader/starrable.transformed.rb +0 -46
  81. data/spec/fixtures/upgrader/subscribable.original.rb +0 -55
  82. data/spec/fixtures/upgrader/subscribable.transformed.rb +0 -51
  83. data/spec/fixtures/upgrader/type_x.original.rb +0 -65
  84. data/spec/fixtures/upgrader/type_x.transformed.rb +0 -56
  85. data/spec/graphql/analysis/analyze_query_spec.rb +0 -261
  86. data/spec/graphql/analysis/ast/field_usage_spec.rb +0 -51
  87. data/spec/graphql/analysis/ast/max_query_complexity_spec.rb +0 -120
  88. data/spec/graphql/analysis/ast/max_query_depth_spec.rb +0 -134
  89. data/spec/graphql/analysis/ast/query_complexity_spec.rb +0 -299
  90. data/spec/graphql/analysis/ast/query_depth_spec.rb +0 -108
  91. data/spec/graphql/analysis/ast_spec.rb +0 -296
  92. data/spec/graphql/analysis/field_usage_spec.rb +0 -62
  93. data/spec/graphql/analysis/max_query_complexity_spec.rb +0 -102
  94. data/spec/graphql/analysis/max_query_depth_spec.rb +0 -103
  95. data/spec/graphql/analysis/query_complexity_spec.rb +0 -301
  96. data/spec/graphql/analysis/query_depth_spec.rb +0 -81
  97. data/spec/graphql/argument_spec.rb +0 -159
  98. data/spec/graphql/authorization_spec.rb +0 -974
  99. data/spec/graphql/backtrace_spec.rb +0 -206
  100. data/spec/graphql/base_type_spec.rb +0 -171
  101. data/spec/graphql/boolean_type_spec.rb +0 -21
  102. data/spec/graphql/compatibility/execution_specification_spec.rb +0 -4
  103. data/spec/graphql/compatibility/lazy_execution_specification_spec.rb +0 -4
  104. data/spec/graphql/compatibility/query_parser_specification_spec.rb +0 -6
  105. data/spec/graphql/compatibility/schema_parser_specification_spec.rb +0 -6
  106. data/spec/graphql/define/assign_argument_spec.rb +0 -61
  107. data/spec/graphql/define/instance_definable_spec.rb +0 -203
  108. data/spec/graphql/directive/skip_directive_spec.rb +0 -9
  109. data/spec/graphql/directive_spec.rb +0 -295
  110. data/spec/graphql/enum_type_spec.rb +0 -158
  111. data/spec/graphql/execution/execute_spec.rb +0 -303
  112. data/spec/graphql/execution/instrumentation_spec.rb +0 -212
  113. data/spec/graphql/execution/interpreter_spec.rb +0 -485
  114. data/spec/graphql/execution/lazy/lazy_method_map_spec.rb +0 -57
  115. data/spec/graphql/execution/lazy_spec.rb +0 -247
  116. data/spec/graphql/execution/lookahead_spec.rb +0 -390
  117. data/spec/graphql/execution/multiplex_spec.rb +0 -222
  118. data/spec/graphql/execution/typecast_spec.rb +0 -47
  119. data/spec/graphql/execution_error_spec.rb +0 -329
  120. data/spec/graphql/field_spec.rb +0 -246
  121. data/spec/graphql/float_type_spec.rb +0 -16
  122. data/spec/graphql/function_spec.rb +0 -152
  123. data/spec/graphql/id_type_spec.rb +0 -33
  124. data/spec/graphql/input_object_type_spec.rb +0 -25
  125. data/spec/graphql/int_type_spec.rb +0 -35
  126. data/spec/graphql/interface_type_spec.rb +0 -196
  127. data/spec/graphql/internal_representation/print_spec.rb +0 -41
  128. data/spec/graphql/internal_representation/rewrite_spec.rb +0 -381
  129. data/spec/graphql/introspection/directive_type_spec.rb +0 -66
  130. data/spec/graphql/introspection/input_value_type_spec.rb +0 -144
  131. data/spec/graphql/introspection/introspection_query_spec.rb +0 -64
  132. data/spec/graphql/introspection/schema_type_spec.rb +0 -57
  133. data/spec/graphql/introspection/type_type_spec.rb +0 -155
  134. data/spec/graphql/language/block_string_spec.rb +0 -70
  135. data/spec/graphql/language/definition_slice_spec.rb +0 -226
  136. data/spec/graphql/language/document_from_schema_definition_spec.rb +0 -770
  137. data/spec/graphql/language/equality_spec.rb +0 -84
  138. data/spec/graphql/language/generation_spec.rb +0 -38
  139. data/spec/graphql/language/lexer_spec.rb +0 -153
  140. data/spec/graphql/language/nodes_spec.rb +0 -67
  141. data/spec/graphql/language/parser_spec.rb +0 -183
  142. data/spec/graphql/language/printer_spec.rb +0 -215
  143. data/spec/graphql/language/visitor_spec.rb +0 -419
  144. data/spec/graphql/list_type_spec.rb +0 -57
  145. data/spec/graphql/non_null_type_spec.rb +0 -48
  146. data/spec/graphql/object_type_spec.rb +0 -197
  147. data/spec/graphql/query/arguments_spec.rb +0 -346
  148. data/spec/graphql/query/context_spec.rb +0 -292
  149. data/spec/graphql/query/executor_spec.rb +0 -341
  150. data/spec/graphql/query/literal_input_spec.rb +0 -91
  151. data/spec/graphql/query/result_spec.rb +0 -29
  152. data/spec/graphql/query/serial_execution/value_resolution_spec.rb +0 -109
  153. data/spec/graphql/query_spec.rb +0 -803
  154. data/spec/graphql/rake_task_spec.rb +0 -59
  155. data/spec/graphql/scalar_type_spec.rb +0 -66
  156. data/spec/graphql/schema/argument_spec.rb +0 -186
  157. data/spec/graphql/schema/build_from_definition_spec.rb +0 -1197
  158. data/spec/graphql/schema/catchall_middleware_spec.rb +0 -32
  159. data/spec/graphql/schema/directive/feature_spec.rb +0 -81
  160. data/spec/graphql/schema/directive/transform_spec.rb +0 -39
  161. data/spec/graphql/schema/enum_spec.rb +0 -83
  162. data/spec/graphql/schema/enum_value_spec.rb +0 -24
  163. data/spec/graphql/schema/field_extension_spec.rb +0 -159
  164. data/spec/graphql/schema/field_spec.rb +0 -319
  165. data/spec/graphql/schema/finder_spec.rb +0 -135
  166. data/spec/graphql/schema/input_object_spec.rb +0 -421
  167. data/spec/graphql/schema/instrumentation_spec.rb +0 -43
  168. data/spec/graphql/schema/interface_spec.rb +0 -215
  169. data/spec/graphql/schema/introspection_system_spec.rb +0 -80
  170. data/spec/graphql/schema/list_spec.rb +0 -73
  171. data/spec/graphql/schema/loader_spec.rb +0 -350
  172. data/spec/graphql/schema/member/accepts_definition_spec.rb +0 -115
  173. data/spec/graphql/schema/member/build_type_spec.rb +0 -63
  174. data/spec/graphql/schema/member/scoped_spec.rb +0 -217
  175. data/spec/graphql/schema/member/type_system_helpers_spec.rb +0 -63
  176. data/spec/graphql/schema/middleware_chain_spec.rb +0 -57
  177. data/spec/graphql/schema/mutation_spec.rb +0 -150
  178. data/spec/graphql/schema/non_null_spec.rb +0 -46
  179. data/spec/graphql/schema/object_spec.rb +0 -355
  180. data/spec/graphql/schema/printer_spec.rb +0 -883
  181. data/spec/graphql/schema/relay_classic_mutation_spec.rb +0 -252
  182. data/spec/graphql/schema/rescue_middleware_spec.rb +0 -88
  183. data/spec/graphql/schema/resolver_spec.rb +0 -743
  184. data/spec/graphql/schema/scalar_spec.rb +0 -101
  185. data/spec/graphql/schema/subscription_spec.rb +0 -505
  186. data/spec/graphql/schema/timeout_middleware_spec.rb +0 -188
  187. data/spec/graphql/schema/timeout_spec.rb +0 -206
  188. data/spec/graphql/schema/traversal_spec.rb +0 -222
  189. data/spec/graphql/schema/type_expression_spec.rb +0 -39
  190. data/spec/graphql/schema/union_spec.rb +0 -72
  191. data/spec/graphql/schema/unique_within_type_spec.rb +0 -44
  192. data/spec/graphql/schema/validation_spec.rb +0 -355
  193. data/spec/graphql/schema/warden_spec.rb +0 -926
  194. data/spec/graphql/schema_spec.rb +0 -169
  195. data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +0 -466
  196. data/spec/graphql/static_validation/rules/argument_names_are_unique_spec.rb +0 -44
  197. data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +0 -112
  198. data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +0 -35
  199. data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +0 -42
  200. data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +0 -167
  201. data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +0 -66
  202. data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +0 -740
  203. data/spec/graphql/static_validation/rules/fragment_names_are_unique_spec.rb +0 -28
  204. data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +0 -52
  205. data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +0 -42
  206. data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +0 -123
  207. data/spec/graphql/static_validation/rules/fragments_are_named_spec.rb +0 -24
  208. data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +0 -56
  209. data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +0 -61
  210. data/spec/graphql/static_validation/rules/mutation_root_exists_spec.rb +0 -39
  211. data/spec/graphql/static_validation/rules/no_definitions_are_present_spec.rb +0 -62
  212. data/spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb +0 -82
  213. data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +0 -98
  214. data/spec/graphql/static_validation/rules/required_input_object_attributes_are_present_spec.rb +0 -86
  215. data/spec/graphql/static_validation/rules/subscription_root_exists_spec.rb +0 -34
  216. data/spec/graphql/static_validation/rules/unique_directives_per_location_spec.rb +0 -188
  217. data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +0 -196
  218. data/spec/graphql/static_validation/rules/variable_names_are_unique_spec.rb +0 -23
  219. data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +0 -236
  220. data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +0 -78
  221. data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +0 -81
  222. data/spec/graphql/static_validation/type_stack_spec.rb +0 -29
  223. data/spec/graphql/static_validation/validator_spec.rb +0 -204
  224. data/spec/graphql/string_type_spec.rb +0 -80
  225. data/spec/graphql/subscriptions/serialize_spec.rb +0 -49
  226. data/spec/graphql/subscriptions_spec.rb +0 -540
  227. data/spec/graphql/tracing/new_relic_tracing_spec.rb +0 -84
  228. data/spec/graphql/tracing/platform_tracing_spec.rb +0 -141
  229. data/spec/graphql/tracing/prometheus_tracing_spec.rb +0 -42
  230. data/spec/graphql/tracing/scout_tracing_spec.rb +0 -17
  231. data/spec/graphql/tracing/skylight_tracing_spec.rb +0 -63
  232. data/spec/graphql/tracing_spec.rb +0 -52
  233. data/spec/graphql/types/big_int_spec.rb +0 -24
  234. data/spec/graphql/types/iso_8601_date_time_spec.rb +0 -137
  235. data/spec/graphql/types/relay/base_edge_spec.rb +0 -33
  236. data/spec/graphql/union_type_spec.rb +0 -211
  237. data/spec/graphql/upgrader/member_spec.rb +0 -583
  238. data/spec/graphql/upgrader/schema_spec.rb +0 -82
  239. data/spec/integration/mongoid/graphql/relay/mongo_relation_connection_spec.rb +0 -528
  240. data/spec/integration/mongoid/spec_helper.rb +0 -2
  241. data/spec/integration/mongoid/star_trek/data.rb +0 -126
  242. data/spec/integration/mongoid/star_trek/schema.rb +0 -424
  243. data/spec/integration/rails/data.rb +0 -110
  244. data/spec/integration/rails/generators/base_generator_test.rb +0 -7
  245. data/spec/integration/rails/generators/graphql/enum_generator_spec.rb +0 -30
  246. data/spec/integration/rails/generators/graphql/install_generator_spec.rb +0 -238
  247. data/spec/integration/rails/generators/graphql/interface_generator_spec.rb +0 -34
  248. data/spec/integration/rails/generators/graphql/loader_generator_spec.rb +0 -59
  249. data/spec/integration/rails/generators/graphql/mutation_generator_spec.rb +0 -71
  250. data/spec/integration/rails/generators/graphql/object_generator_spec.rb +0 -54
  251. data/spec/integration/rails/generators/graphql/scalar_generator_spec.rb +0 -28
  252. data/spec/integration/rails/generators/graphql/union_generator_spec.rb +0 -67
  253. data/spec/integration/rails/graphql/input_object_spec.rb +0 -19
  254. data/spec/integration/rails/graphql/input_object_type_spec.rb +0 -364
  255. data/spec/integration/rails/graphql/query/variables_spec.rb +0 -375
  256. data/spec/integration/rails/graphql/relay/array_connection_spec.rb +0 -309
  257. data/spec/integration/rails/graphql/relay/base_connection_spec.rb +0 -101
  258. data/spec/integration/rails/graphql/relay/connection_instrumentation_spec.rb +0 -80
  259. data/spec/integration/rails/graphql/relay/connection_resolve_spec.rb +0 -79
  260. data/spec/integration/rails/graphql/relay/connection_type_spec.rb +0 -106
  261. data/spec/integration/rails/graphql/relay/edge_spec.rb +0 -10
  262. data/spec/integration/rails/graphql/relay/mutation_spec.rb +0 -387
  263. data/spec/integration/rails/graphql/relay/node_spec.rb +0 -263
  264. data/spec/integration/rails/graphql/relay/page_info_spec.rb +0 -111
  265. data/spec/integration/rails/graphql/relay/range_add_spec.rb +0 -117
  266. data/spec/integration/rails/graphql/relay/relation_connection_spec.rb +0 -837
  267. data/spec/integration/rails/graphql/schema_spec.rb +0 -507
  268. data/spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb +0 -62
  269. data/spec/integration/rails/spec_helper.rb +0 -25
  270. data/spec/spec_helper.rb +0 -116
  271. data/spec/support/dummy/data.rb +0 -45
  272. data/spec/support/dummy/schema.rb +0 -519
  273. data/spec/support/error_bubbling_helpers.rb +0 -23
  274. data/spec/support/global_id.rb +0 -23
  275. data/spec/support/jazz.rb +0 -778
  276. data/spec/support/lazy_helpers.rb +0 -192
  277. data/spec/support/magic_cards/schema.graphql +0 -33
  278. data/spec/support/minimum_input_object.rb +0 -21
  279. data/spec/support/new_relic.rb +0 -27
  280. data/spec/support/parser/filename_example.graphql +0 -5
  281. data/spec/support/parser/filename_example_error_1.graphql +0 -4
  282. data/spec/support/parser/filename_example_error_2.graphql +0 -5
  283. data/spec/support/parser/filename_example_invalid_utf8.graphql +0 -1
  284. data/spec/support/skylight.rb +0 -39
  285. data/spec/support/star_wars/schema.rb +0 -464
  286. data/spec/support/static_validation_helpers.rb +0 -32
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe GraphQL::Execution::Lazy::LazyMethodMap do
5
- def self.test_lazy_method_map
6
- it "handles multithreaded access" do
7
- a = Class.new
8
- b = Class.new(a)
9
- c = Class.new(b)
10
- lazy_method_map.set(a, :a)
11
- threads = 1000.times.map do |i|
12
- Thread.new {
13
- d = Class.new(c)
14
- assert_equal :a, lazy_method_map.get(d.new)
15
- }
16
- end
17
- threads.map(&:join)
18
- end
19
-
20
- it "dups" do
21
- a = Class.new
22
- b = Class.new(a)
23
- c = Class.new(b)
24
- lazy_method_map.set(a, :a)
25
- lazy_method_map.get(b.new)
26
- lazy_method_map.get(c.new)
27
-
28
- dup_map = lazy_method_map.dup
29
- assert_equal 3, dup_map.instance_variable_get(:@storage).size
30
- assert_equal :a, dup_map.get(a.new)
31
- assert_equal :a, dup_map.get(b.new)
32
- assert_equal :a, dup_map.get(c.new)
33
- end
34
- end
35
-
36
- describe "with a plain hash" do
37
- let(:lazy_method_map) { GraphQL::Execution::Lazy::LazyMethodMap.new(use_concurrent: false) }
38
- test_lazy_method_map
39
-
40
- it "has a Ruby Hash inside" do
41
- storage = lazy_method_map
42
- .instance_variable_get(:@storage)
43
- .instance_variable_get(:@storage)
44
- assert_instance_of Hash, storage
45
- end
46
- end
47
-
48
- describe "with a Concurrent::Map" do
49
- let(:lazy_method_map) { GraphQL::Execution::Lazy::LazyMethodMap.new(use_concurrent: true) }
50
- test_lazy_method_map
51
-
52
- it "has a Concurrent::Map inside" do
53
- storage = lazy_method_map.instance_variable_get(:@storage)
54
- assert_instance_of Concurrent::Map, storage
55
- end
56
- end
57
- end
@@ -1,247 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe GraphQL::Execution::Lazy do
5
- include LazyHelpers
6
-
7
- describe "resolving" do
8
- it "calls value handlers" do
9
- res = run_query('{ int(value: 2, plus: 1) }')
10
- assert_equal 3, res["data"]["int"]
11
- end
12
-
13
- it "Works with Query.new" do
14
- query_str = '{ int(value: 2, plus: 1) }'
15
- query = GraphQL::Query.new(LazyHelpers::LazySchema, query_str)
16
- res = query.result
17
- assert_equal 3, res["data"]["int"]
18
- end
19
-
20
- it "can do nested lazy values" do
21
- res = run_query %|
22
- {
23
- a: nestedSum(value: 3) {
24
- value
25
- nestedSum(value: 7) {
26
- value
27
- nestedSum(value: 1) {
28
- value
29
- nestedSum(value: -50) {
30
- value
31
- }
32
- }
33
- }
34
- }
35
- b: nestedSum(value: 2) {
36
- value
37
- nestedSum(value: 11) {
38
- value
39
- nestedSum(value: 2) {
40
- value
41
- nestedSum(value: -50) {
42
- value
43
- }
44
- }
45
- }
46
- }
47
-
48
- c: listSum(values: [1,2]) {
49
- nestedSum(value: 3) {
50
- value
51
- }
52
- }
53
- }
54
- |
55
-
56
- expected_data = {
57
- "a"=>{"value"=>14, "nestedSum"=>{
58
- "value"=>46,
59
- "nestedSum"=>{
60
- "value"=>95,
61
- "nestedSum"=>{"value"=>90}
62
- }
63
- }},
64
- "b"=>{"value"=>14, "nestedSum"=>{
65
- "value"=>46,
66
- "nestedSum"=>{
67
- "value"=>95,
68
- "nestedSum"=>{"value"=>90}
69
- }
70
- }},
71
- "c"=>[
72
- {"nestedSum"=>{"value"=>14}},
73
- {"nestedSum"=>{"value"=>14}}
74
- ],
75
- }
76
-
77
- assert_equal expected_data, res["data"]
78
- end
79
-
80
- # This only works with the interpreter
81
- if TESTING_INTERPRETER
82
- [
83
- [1, 2, LazyHelpers::MAGIC_NUMBER_WITH_LAZY_AUTHORIZED_HOOK],
84
- [2, LazyHelpers::MAGIC_NUMBER_WITH_LAZY_AUTHORIZED_HOOK, 1],
85
- [LazyHelpers::MAGIC_NUMBER_WITH_LAZY_AUTHORIZED_HOOK, 1, 2],
86
- ].each do |ordered_values|
87
- it "resolves each field at one depth before proceeding to the next depth (using #{ordered_values})" do
88
- res = run_query <<-GRAPHQL, variables: { values: ordered_values }
89
- query($values: [Int!]!) {
90
- listSum(values: $values) {
91
- nestedSum(value: 3) {
92
- value
93
- }
94
- }
95
- }
96
- GRAPHQL
97
-
98
- # Even though magic number `44`'s `.authorized?` hook returns a lazy value,
99
- # these fields should be resolved together and return the same value.
100
- assert_equal 56, res["data"]["listSum"][0]["nestedSum"]["value"]
101
- assert_equal 56, res["data"]["listSum"][1]["nestedSum"]["value"]
102
- assert_equal 56, res["data"]["listSum"][2]["nestedSum"]["value"]
103
- end
104
- end
105
-
106
- it "Handles fields that return nil" do
107
- values = [
108
- LazyHelpers::MAGIC_NUMBER_THAT_RETURNS_NIL,
109
- LazyHelpers::MAGIC_NUMBER_WITH_LAZY_AUTHORIZED_HOOK,
110
- 1,
111
- 2,
112
- ]
113
-
114
- res = run_query <<-GRAPHQL, variables: { values: values }
115
- query($values: [Int!]!) {
116
- listSum(values: $values) {
117
- nullableNestedSum(value: 3) {
118
- value
119
- }
120
- }
121
- }
122
- GRAPHQL
123
-
124
- values = res["data"]["listSum"].map { |s| s && s["nullableNestedSum"]["value"] }
125
- assert_equal [nil, 56, 56, 56], values
126
- end
127
- end
128
-
129
- it "propagates nulls to the root" do
130
- res = run_query %|
131
- {
132
- nestedSum(value: 1) {
133
- value
134
- nestedSum(value: 2) {
135
- nestedSum(value: 13) {
136
- value
137
- }
138
- }
139
- }
140
- }|
141
-
142
- assert_equal(nil, res["data"])
143
- assert_equal 1, res["errors"].length
144
- end
145
-
146
- it "propagates partial nulls" do
147
- res = run_query %|
148
- {
149
- nullableNestedSum(value: 1) {
150
- value
151
- nullableNestedSum(value: 2) {
152
- ns: nestedSum(value: 13) {
153
- value
154
- }
155
- }
156
- }
157
- }|
158
-
159
- expected_data = {
160
- "nullableNestedSum" => {
161
- "value" => 1,
162
- "nullableNestedSum" => nil,
163
- }
164
- }
165
- assert_equal(expected_data, res["data"])
166
- assert_equal 1, res["errors"].length
167
- end
168
-
169
- it "handles raised errors" do
170
- res = run_query %|
171
- {
172
- a: nullableNestedSum(value: 1) { value }
173
- b: nullableNestedSum(value: 13) { value }
174
- c: nullableNestedSum(value: 2) { value }
175
- }|
176
-
177
- expected_data = {
178
- "a" => { "value" => 3 },
179
- "b" => nil,
180
- "c" => { "value" => 3 },
181
- }
182
- assert_equal expected_data, res["data"]
183
-
184
- expected_errors = [{
185
- "message"=>"13 is unlucky",
186
- "locations"=>[{"line"=>4, "column"=>9}],
187
- "path"=>["b"],
188
- }]
189
- assert_equal expected_errors, res["errors"]
190
- end
191
-
192
- it "resolves mutation fields right away" do
193
- res = run_query %|
194
- {
195
- a: nestedSum(value: 2) { value }
196
- b: nestedSum(value: 4) { value }
197
- c: nestedSum(value: 6) { value }
198
- }|
199
-
200
- assert_equal [12, 12, 12], res["data"].values.map { |d| d["value"] }
201
-
202
- res = run_query %|
203
- mutation {
204
- a: nestedSum(value: 2) { value }
205
- b: nestedSum(value: 4) { value }
206
- c: nestedSum(value: 6) { value }
207
- }
208
- |
209
-
210
- assert_equal [2, 4, 6], res["data"].values.map { |d| d["value"] }
211
- end
212
- end
213
-
214
- describe "Schema#sync_lazy(object)" do
215
- it "Passes objects to that hook at runtime" do
216
- res = run_query <<-GRAPHQL
217
- {
218
- a: nullableNestedSum(value: 1001) { value }
219
- b: nullableNestedSum(value: 1013) { value }
220
- c: nullableNestedSum(value: 1002) { value }
221
- }
222
- GRAPHQL
223
-
224
- # This odd, non-adding behavior is hacked into `#sync_lazy`
225
- assert_equal 101, res["data"]["a"]["value"]
226
- assert_equal 113, res["data"]["b"]["value"]
227
- assert_equal 102, res["data"]["c"]["value"]
228
- end
229
- end
230
-
231
- describe "LazyMethodMap" do
232
- class SubWrapper < LazyHelpers::Wrapper; end
233
-
234
- let(:map) { GraphQL::Execution::Lazy::LazyMethodMap.new }
235
-
236
- it "finds methods for classes and subclasses" do
237
- map.set(LazyHelpers::Wrapper, :item)
238
- map.set(LazyHelpers::SumAll, :value)
239
- b = LazyHelpers::Wrapper.new(1)
240
- sub_b = LazyHelpers::Wrapper.new(2)
241
- s = LazyHelpers::SumAll.new(3)
242
- assert_equal(:item, map.get(b))
243
- assert_equal(:item, map.get(sub_b))
244
- assert_equal(:value, map.get(s))
245
- end
246
- end
247
- end
@@ -1,390 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe GraphQL::Execution::Lookahead do
5
- module LookaheadTest
6
- DATA = [
7
- OpenStruct.new(name: "Cardinal", is_waterfowl: false, similar_species_names: ["Scarlet Tanager"], genus: OpenStruct.new(latin_name: "Piranga")),
8
- OpenStruct.new(name: "Scarlet Tanager", is_waterfowl: false, similar_species_names: ["Cardinal"], genus: OpenStruct.new(latin_name: "Cardinalis")),
9
- OpenStruct.new(name: "Great Egret", is_waterfowl: false, similar_species_names: ["Great Blue Heron"], genus: OpenStruct.new(latin_name: "Ardea")),
10
- OpenStruct.new(name: "Great Blue Heron", is_waterfowl: true, similar_species_names: ["Great Egret"], genus: OpenStruct.new(latin_name: "Ardea")),
11
- ]
12
-
13
- def DATA.find_by_name(name)
14
- DATA.find { |b| b.name == name }
15
- end
16
-
17
- module Node
18
- include GraphQL::Schema::Interface
19
- field :id, ID, null: false
20
- end
21
-
22
- class BirdGenus < GraphQL::Schema::Object
23
- field :name, String, null: false
24
- field :latin_name, String, null: false
25
- field :id, ID, null: false, method: :latin_name
26
- end
27
-
28
- class BirdSpecies < GraphQL::Schema::Object
29
- field :name, String, null: false
30
- field :id, ID, null: false, method: :name
31
- field :is_waterfowl, Boolean, null: false
32
- field :similar_species, [BirdSpecies], null: false
33
-
34
- def similar_species
35
- object.similar_species_names.map { |n| DATA.find_by_name(n) }
36
- end
37
-
38
- field :genus, BirdGenus, null: false,
39
- extras: [:lookahead]
40
-
41
- def genus(lookahead:)
42
- if lookahead.selects?(:latin_name)
43
- context[:lookahead_latin_name] += 1
44
- end
45
- object.genus
46
- end
47
- end
48
-
49
- class Query < GraphQL::Schema::Object
50
- field :find_bird_species, BirdSpecies, null: true do
51
- argument :by_name, String, required: true
52
- end
53
-
54
- def find_bird_species(by_name:)
55
- DATA.find_by_name(by_name)
56
- end
57
-
58
- field :node, Node, null: true do
59
- argument :id, ID, required: true
60
- end
61
-
62
- def node(id:)
63
- if (node = DATA.find_by_name(id))
64
- node
65
- else
66
- DATA.map { |d| d.genus }.select { |g| g.name == id }
67
- end
68
- end
69
- end
70
-
71
- class LookaheadInstrumenter
72
- def self.before_query(query)
73
- query.context[:root_lookahead_selections] = query.lookahead.selections
74
- end
75
-
76
- def self.after_query(q)
77
- end
78
- end
79
-
80
- class Schema < GraphQL::Schema
81
- query(Query)
82
- instrument :query, LookaheadInstrumenter
83
- if TESTING_INTERPRETER
84
- use GraphQL::Execution::Interpreter
85
- end
86
- end
87
- end
88
-
89
- describe "looking ahead" do
90
- let(:document) {
91
- GraphQL.parse <<-GRAPHQL
92
- query($name: String!){
93
- findBirdSpecies(byName: $name) {
94
- name
95
- similarSpecies {
96
- likesWater: isWaterfowl
97
- }
98
- }
99
- t: __typename
100
- }
101
- GRAPHQL
102
- }
103
- let(:query) {
104
- GraphQL::Query.new(LookaheadTest::Schema, document: document, variables: { name: "Cardinal" })
105
- }
106
-
107
- it "has a good test setup" do
108
- res = query.result
109
- assert_equal [false], res["data"]["findBirdSpecies"]["similarSpecies"].map { |s| s["likesWater"] }
110
- end
111
-
112
- it "can detect fields on objects with symbol or string" do
113
- lookahead = query.lookahead.selection("findBirdSpecies")
114
- assert_equal true, lookahead.selects?("similarSpecies")
115
- assert_equal true, lookahead.selects?(:similar_species)
116
- assert_equal false, lookahead.selects?("isWaterfowl")
117
- assert_equal false, lookahead.selects?(:is_waterfowl)
118
- end
119
-
120
- it "detects by name, not by alias" do
121
- assert_equal true, query.lookahead.selects?("__typename")
122
- end
123
-
124
- describe "fields on interfaces" do
125
- let(:document) {
126
- GraphQL.parse <<-GRAPHQL
127
- query {
128
- node(id: "Cardinal") {
129
- id
130
- ... on BirdSpecies {
131
- name
132
- }
133
- ...Other
134
- }
135
- }
136
- fragment Other on BirdGenus {
137
- latinName
138
- }
139
- GRAPHQL
140
- }
141
-
142
- it "finds fields on object types and interface types" do
143
- node_lookahead = query.lookahead.selection("node")
144
- assert_equal [:id, :name, :latin_name], node_lookahead.selections.map(&:name)
145
- end
146
- end
147
-
148
- describe "inspect" do
149
- it "works for root lookaheads" do
150
- assert_includes query.lookahead.inspect, "#<GraphQL::Execution::Lookahead @root_type="
151
- end
152
-
153
- it "works for field lookaheads" do
154
- assert_includes query.lookahead.selection(:find_bird_species).inspect, "#<GraphQL::Execution::Lookahead @field="
155
- end
156
- end
157
-
158
- describe "constraints by arguments" do
159
- let(:lookahead) do
160
- query.lookahead
161
- end
162
-
163
- it "is true without constraints" do
164
- assert_equal true, lookahead.selects?("findBirdSpecies")
165
- end
166
-
167
- it "is true when all given constraints are satisfied" do
168
- assert_equal true, lookahead.selects?(:find_bird_species, arguments: { by_name: "Cardinal" })
169
- assert_equal true, lookahead.selects?("findBirdSpecies", arguments: { "byName" => "Cardinal" })
170
- end
171
-
172
- it "is true when no constraints are given" do
173
- assert_equal true, lookahead.selects?(:find_bird_species, arguments: {})
174
- assert_equal true, lookahead.selects?("__typename", arguments: {})
175
- end
176
-
177
- it "is false when some given constraints aren't satisfied" do
178
- assert_equal false, lookahead.selects?(:find_bird_species, arguments: { by_name: "Chickadee" })
179
- assert_equal false, lookahead.selects?(:find_bird_species, arguments: { by_name: "Cardinal", other: "Nonsense" })
180
- end
181
-
182
- describe "with literal values" do
183
- let(:document) {
184
- GraphQL.parse <<-GRAPHQL
185
- {
186
- findBirdSpecies(byName: "Great Blue Heron") {
187
- isWaterfowl
188
- }
189
- }
190
- GRAPHQL
191
- }
192
-
193
- it "works" do
194
- assert_equal true, lookahead.selects?(:find_bird_species, arguments: { by_name: "Great Blue Heron" })
195
- end
196
- end
197
- end
198
-
199
- it "can do a chained lookahead" do
200
- next_lookahead = query.lookahead.selection(:find_bird_species, arguments: { by_name: "Cardinal" })
201
- assert_equal true, next_lookahead.selected?
202
- nested_selection = next_lookahead.selection(:similar_species).selection(:is_waterfowl, arguments: {})
203
- assert_equal true, nested_selection.selected?
204
- assert_equal false, next_lookahead.selection(:similar_species).selection(:name).selected?
205
- end
206
-
207
- it "can detect fields on lists with symbol or string" do
208
- assert_equal true, query.lookahead.selection(:find_bird_species).selection(:similar_species).selection(:is_waterfowl).selected?
209
- assert_equal true, query.lookahead.selection("findBirdSpecies").selection("similarSpecies").selection("isWaterfowl").selected?
210
- end
211
-
212
- describe "merging branches and fragments" do
213
- let(:document) {
214
- GraphQL.parse <<-GRAPHQL
215
- {
216
- findBirdSpecies(name: "Cardinal") {
217
- similarSpecies {
218
- __typename
219
- }
220
- }
221
- ...F
222
- ... {
223
- findBirdSpecies(name: "Cardinal") {
224
- similarSpecies {
225
- isWaterfowl
226
- }
227
- }
228
- }
229
- }
230
-
231
- fragment F on Query {
232
- findBirdSpecies(name: "Cardinal") {
233
- similarSpecies {
234
- name
235
- }
236
- }
237
- }
238
- GRAPHQL
239
- }
240
-
241
- it "finds selections using merging" do
242
- merged_lookahead = query.lookahead.selection(:find_bird_species).selection(:similar_species)
243
- assert merged_lookahead.selects?(:__typename)
244
- assert merged_lookahead.selects?(:is_waterfowl)
245
- assert merged_lookahead.selects?(:name)
246
- end
247
- end
248
- end
249
-
250
- describe "in queries" do
251
- it "can be an extra" do
252
- query_str = <<-GRAPHQL
253
- {
254
- cardinal: findBirdSpecies(byName: "Cardinal") {
255
- genus { __typename }
256
- }
257
- scarletTanager: findBirdSpecies(byName: "Scarlet Tanager") {
258
- genus { latinName }
259
- }
260
- greatBlueHeron: findBirdSpecies(byName: "Great Blue Heron") {
261
- genus { latinName }
262
- }
263
- }
264
- GRAPHQL
265
- context = {lookahead_latin_name: 0}
266
- res = LookaheadTest::Schema.execute(query_str, context: context)
267
- refute res.key?("errors")
268
- assert_equal 2, context[:lookahead_latin_name]
269
- assert_equal [:find_bird_species], context[:root_lookahead_selections].map(&:name).uniq
270
- assert_equal(
271
- [{ by_name: "Cardinal" }, { by_name: "Scarlet Tanager" }, { by_name: "Great Blue Heron" }],
272
- context[:root_lookahead_selections].map(&:arguments)
273
- )
274
- end
275
-
276
- it "works for invalid queries" do
277
- context = {lookahead_latin_name: 0}
278
- res = LookaheadTest::Schema.execute("{ doesNotExist }", context: context)
279
- assert res.key?("errors")
280
- assert_equal 0, context[:lookahead_latin_name]
281
- end
282
- end
283
-
284
- describe '#selections' do
285
- let(:document) {
286
- GraphQL.parse <<-GRAPHQL
287
- query {
288
- findBirdSpecies(byName: "Laughing Gull") {
289
- name
290
- similarSpecies {
291
- likesWater: isWaterfowl
292
- }
293
- }
294
- }
295
- GRAPHQL
296
- }
297
-
298
- def query(doc = document)
299
- GraphQL::Query.new(LookaheadTest::Schema, document: doc)
300
- end
301
-
302
- it "provides a list of all selections" do
303
- ast_node = document.definitions.first.selections.first
304
- field = LookaheadTest::Query.fields["findBirdSpecies"]
305
- lookahead = GraphQL::Execution::Lookahead.new(query: query, ast_nodes: [ast_node], field: field)
306
- assert_equal [:name, :similar_species], lookahead.selections.map(&:name)
307
- end
308
-
309
- it "filters outs selections which do not match arguments" do
310
- ast_node = document.definitions.first
311
- lookahead = GraphQL::Execution::Lookahead.new(query: query, ast_nodes: [ast_node], root_type: LookaheadTest::Query)
312
- arguments = { by_name: "Cardinal" }
313
-
314
- assert_equal lookahead.selections(arguments: arguments).map(&:name), []
315
- end
316
-
317
- it "includes selections which match arguments" do
318
- ast_node = document.definitions.first
319
- lookahead = GraphQL::Execution::Lookahead.new(query: query, ast_nodes: [ast_node], root_type: LookaheadTest::Query)
320
- arguments = { by_name: "Laughing Gull" }
321
-
322
- assert_equal lookahead.selections(arguments: arguments).map(&:name), [:find_bird_species]
323
- end
324
-
325
- it 'handles duplicate selections across fragments' do
326
- doc = GraphQL.parse <<-GRAPHQL
327
- query {
328
- ... on Query {
329
- ...MoreFields
330
- }
331
- }
332
-
333
- fragment MoreFields on Query {
334
- findBirdSpecies(byName: "Laughing Gull") {
335
- name
336
- }
337
- findBirdSpecies(byName: "Laughing Gull") {
338
- ...EvenMoreFields
339
- }
340
- }
341
-
342
- fragment EvenMoreFields on BirdSpecies {
343
- similarSpecies {
344
- likesWater: isWaterfowl
345
- }
346
- }
347
- GRAPHQL
348
-
349
- lookahead = query(doc).lookahead
350
-
351
- root_selections = lookahead.selections
352
- assert_equal [:find_bird_species], root_selections.map(&:name), "Selections are merged"
353
- assert_equal 2, root_selections.first.ast_nodes.size, "It represents both nodes"
354
-
355
- assert_equal [:name, :similar_species], root_selections.first.selections.map(&:name), "Subselections are merged"
356
- end
357
-
358
- it "avoids merging selections for same field name on distinct types" do
359
- query = GraphQL::Query.new(LookaheadTest::Schema, <<-GRAPHQL)
360
- query {
361
- node(id: "Cardinal") {
362
- ... on BirdSpecies {
363
- name
364
- }
365
- ... on BirdGenus {
366
- name
367
- }
368
- id
369
- }
370
- }
371
- GRAPHQL
372
-
373
- node_lookahead = query.lookahead.selection("node")
374
- assert_equal(
375
- [[LookaheadTest::Node, :id], [LookaheadTest::BirdSpecies, :name], [LookaheadTest::BirdGenus, :name]],
376
- node_lookahead.selections.map { |s| [s.owner_type, s.name] }
377
- )
378
- end
379
-
380
- it "works for missing selections" do
381
- ast_node = document.definitions.first.selections.first
382
- field = LookaheadTest::Query.fields["findBirdSpecies"]
383
- lookahead = GraphQL::Execution::Lookahead.new(query: query, ast_nodes: [ast_node], field: field)
384
- null_lookahead = lookahead.selection(:genus)
385
- # This is an implementation detail, but I want to make sure the test is set up right
386
- assert_instance_of GraphQL::Execution::Lookahead::NullLookahead, null_lookahead
387
- assert_equal [], null_lookahead.selections
388
- end
389
- end
390
- end