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,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require './lib/graphql/upgrader/schema.rb'
5
-
6
- describe GraphQL::Upgrader::Schema do
7
- def upgrade(old)
8
- GraphQL::Upgrader::Schema.new(old).upgrade
9
- end
10
-
11
- it 'updates the definition' do
12
- old = %{
13
- StarWarsSchema = GraphQL::Schema.define do
14
- end
15
- }
16
- new = %{
17
- class StarWarsSchema < GraphQL::Schema
18
- end
19
- }
20
-
21
- assert_equal upgrade(old), new
22
- end
23
-
24
- it 'updates the resolve_type' do
25
- old = %{
26
- StarWarsSchema = GraphQL::Schema.define do
27
- resolve_type ->(obj, ctx) do
28
- nil
29
- end
30
- end
31
- }
32
- new = %{
33
- class StarWarsSchema < GraphQL::Schema
34
- def self.resolve_type(obj, ctx)
35
- nil
36
- end
37
- end
38
- }
39
-
40
- assert_equal upgrade(old), new
41
- end
42
-
43
- it 'updates the object_from_id' do
44
- old = %{
45
- StarWarsSchema = GraphQL::Schema.define do
46
- object_from_id ->(id, ctx) do
47
- nil
48
- end
49
- end
50
- }
51
- new = %{
52
- class StarWarsSchema < GraphQL::Schema
53
- def self.object_from_id(id, ctx)
54
- nil
55
- end
56
- end
57
- }
58
-
59
- assert_equal upgrade(old), new
60
- end
61
-
62
- it 'updates the id_from_object' do
63
- old = %{
64
- StarWarsSchema = GraphQL::Schema.define do
65
- id_from_object -> (object, type_definition, ctx) do
66
- nil
67
- end
68
- end
69
- }
70
- new = %{
71
- class StarWarsSchema < GraphQL::Schema
72
- def self.id_from_object(object, type_definition, ctx)
73
- nil
74
- end
75
- end
76
- }
77
-
78
- assert_equal upgrade(old), new
79
- end
80
-
81
-
82
- end
@@ -1,528 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
-
4
- describe GraphQL::Relay::MongoRelationConnection do
5
- def get_names(result)
6
- ships = result["data"]["federation"]["bases"]["edges"]
7
- ships.map { |e| e["node"]["name"] }
8
- end
9
-
10
- def get_residents(ship)
11
- ship["residents"]["edges"].map { |e| e["node"]["name"] }
12
- end
13
-
14
- def get_ships_residents(result)
15
- ships = result["data"]["federation"]["bases"]["edges"]
16
- Hash[ships.map { |e| [e["node"]["name"], get_residents(e["node"])] }]
17
- end
18
-
19
- def get_page_info(result)
20
- result["data"]["federation"]["bases"]["pageInfo"]
21
- end
22
-
23
- def get_first_cursor(result)
24
- result["data"]["federation"]["bases"]["edges"].first["cursor"]
25
- end
26
-
27
- def get_last_cursor(result)
28
- result["data"]["federation"]["bases"]["edges"].last["cursor"]
29
- end
30
-
31
- describe "results" do
32
- let(:query_string) {%|
33
- query getShips($first: Int, $after: String, $last: Int, $before: String, $nameIncludes: String){
34
- federation {
35
- bases(first: $first, after: $after, last: $last, before: $before, nameIncludes: $nameIncludes) {
36
- ... basesConnection
37
- }
38
- }
39
- }
40
-
41
- fragment basesConnection on BasesConnectionWithTotalCount {
42
- totalCount,
43
- edges {
44
- cursor
45
- node {
46
- name
47
- }
48
- },
49
- pageInfo {
50
- hasNextPage
51
- hasPreviousPage
52
- startCursor
53
- endCursor
54
- }
55
- }
56
- |}
57
-
58
- it 'limits the result' do
59
- result = star_trek_query(query_string, "first" => 2)
60
- assert_equal(2, get_names(result).length)
61
- assert_equal(true, get_page_info(result)["hasNextPage"])
62
- assert_equal(false, get_page_info(result)["hasPreviousPage"])
63
- assert_equal("MQ", get_page_info(result)["startCursor"])
64
- assert_equal("Mg", get_page_info(result)["endCursor"])
65
- assert_equal("MQ", get_first_cursor(result))
66
- assert_equal("Mg", get_last_cursor(result))
67
-
68
- result = star_trek_query(query_string, "first" => 3)
69
- assert_equal(3, get_names(result).length)
70
- assert_equal(false, get_page_info(result)["hasNextPage"])
71
- assert_equal(false, get_page_info(result)["hasPreviousPage"])
72
- assert_equal("MQ", get_page_info(result)["startCursor"])
73
- assert_equal("Mw", get_page_info(result)["endCursor"])
74
- assert_equal("MQ", get_first_cursor(result))
75
- assert_equal("Mw", get_last_cursor(result))
76
- end
77
-
78
- it 'provides custom fields on the connection type' do
79
- result = star_trek_query(query_string, "first" => 2)
80
- assert_equal(
81
- StarTrek::Base.where(faction_id: 1).count,
82
- result["data"]["federation"]["bases"]["totalCount"]
83
- )
84
- end
85
-
86
- it "provides bidirectional_pagination" do
87
- result = star_trek_query(query_string, "first" => 1)
88
- last_cursor = get_last_cursor(result)
89
-
90
- result = star_trek_query(query_string, "first" => 1, "after" => last_cursor)
91
- assert_equal true, get_page_info(result)["hasNextPage"]
92
- assert_equal false, get_page_info(result)["hasPreviousPage"]
93
-
94
- result = with_bidirectional_pagination {
95
- star_trek_query(query_string, "first" => 1, "after" => last_cursor)
96
- }
97
- assert_equal true, get_page_info(result)["hasNextPage"]
98
- assert_equal true, get_page_info(result)["hasPreviousPage"]
99
-
100
- last_cursor = get_last_cursor(result)
101
- result = with_bidirectional_pagination {
102
- star_trek_query(query_string, "last" => 1, "before" => last_cursor)
103
- }
104
- assert_equal true, get_page_info(result)["hasNextPage"]
105
- assert_equal false, get_page_info(result)["hasPreviousPage"]
106
-
107
- result = star_trek_query(query_string, "first" => 100)
108
- last_cursor = get_last_cursor(result)
109
-
110
- result = star_trek_query(query_string, "last" => 1, "before" => last_cursor)
111
- assert_equal false, get_page_info(result)["hasNextPage"]
112
- assert_equal true, get_page_info(result)["hasPreviousPage"]
113
-
114
- result = with_bidirectional_pagination {
115
- star_trek_query(query_string, "last" => 1, "before" => last_cursor)
116
- }
117
- assert_equal true, get_page_info(result)["hasNextPage"]
118
- assert_equal true, get_page_info(result)["hasPreviousPage"]
119
- end
120
-
121
- it 'slices the result' do
122
- result = star_trek_query(query_string, "first" => 2)
123
- assert_equal(["Deep Space Station K-7", "Regula I"], get_names(result))
124
-
125
- # After the last result, find the next 2:
126
- last_cursor = get_last_cursor(result)
127
-
128
- result = star_trek_query(query_string, "after" => last_cursor, "first" => 2)
129
- assert_equal(["Deep Space Nine"], get_names(result))
130
-
131
- last_cursor = get_last_cursor(result)
132
-
133
- result = star_trek_query(query_string, "before" => last_cursor, "last" => 1)
134
- assert_equal(["Regula I"], get_names(result))
135
-
136
- result = star_trek_query(query_string, "before" => last_cursor, "last" => 2)
137
- assert_equal(["Deep Space Station K-7", "Regula I"], get_names(result))
138
-
139
- result = star_trek_query(query_string, "before" => last_cursor, "last" => 10)
140
- assert_equal(["Deep Space Station K-7", "Regula I"], get_names(result))
141
-
142
- result = star_trek_query(query_string, "last" => 2)
143
- assert_equal(["Regula I", "Deep Space Nine"], get_names(result))
144
-
145
- result = star_trek_query(query_string, "last" => 10)
146
- assert_equal(["Deep Space Station K-7", "Regula I", "Deep Space Nine"], get_names(result))
147
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"])
148
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasPreviousPage"])
149
- end
150
-
151
- it 'works with before and after specified together' do
152
- result = star_trek_query(query_string, "first" => 2)
153
- assert_equal(["Deep Space Station K-7", "Regula I"], get_names(result))
154
-
155
- first_cursor = get_last_cursor(result)
156
-
157
- # There is no records between before and after if they point to the same cursor
158
- result = star_trek_query(query_string, "before" => first_cursor, "after" => first_cursor, "last" => 2)
159
- assert_equal([], get_names(result))
160
-
161
- result = star_trek_query(query_string, "after" => first_cursor, "first" => 2)
162
- assert_equal(["Deep Space Nine"], get_names(result))
163
-
164
- second_cursor = get_last_cursor(result)
165
-
166
- result = star_trek_query(query_string, "after" => first_cursor, "before" => second_cursor, "first" => 3)
167
- assert_equal([], get_names(result)) # TODO: test fails. fixme
168
- end
169
-
170
- it 'handles cursors above the bounds of the array' do
171
- overreaching_cursor = Base64.strict_encode64("100")
172
- result = star_trek_query(query_string, "after" => overreaching_cursor, "first" => 2)
173
- assert_equal([], get_names(result))
174
- end
175
-
176
- it 'handles cursors below the bounds of the array' do
177
- underreaching_cursor = Base64.strict_encode64("1")
178
- result = star_trek_query(query_string, "before" => underreaching_cursor, "first" => 2)
179
- assert_equal([], get_names(result))
180
- end
181
-
182
-
183
- it 'handles grouped connections with only last argument' do
184
- grouped_conn_query = <<-GRAPHQL
185
- query {
186
- newestBasesGroupedByFaction(last: 2) {
187
- edges {
188
- node {
189
- name
190
- }
191
- }
192
- }
193
- }
194
- GRAPHQL
195
-
196
- result = star_trek_query(grouped_conn_query)
197
- names = result['data']['newestBasesGroupedByFaction']['edges'].map { |edge| edge['node']['name'] }
198
- assert_equal(['Ganalda Space Station', 'Deep Space Nine'], names)
199
- end
200
-
201
- it "applies custom arguments" do
202
- result = star_trek_query(query_string, "first" => 1, "nameIncludes" => "eep")
203
- assert_equal(["Deep Space Station K-7"], get_names(result))
204
-
205
- after = get_last_cursor(result)
206
-
207
- result = star_trek_query(query_string, "first" => 2, "nameIncludes" => "eep", "after" => after )
208
- assert_equal(["Deep Space Nine"], get_names(result))
209
- before = get_last_cursor(result)
210
-
211
- result = star_trek_query(query_string, "last" => 1, "nameIncludes" => "eep", "before" => before)
212
- assert_equal(["Deep Space Station K-7"], get_names(result))
213
- end
214
-
215
- it 'works without first/last/after/before' do
216
- result = star_trek_query(query_string)
217
-
218
- assert_equal(3, result["data"]["federation"]["bases"]["edges"].length)
219
- end
220
-
221
- describe "applying max_page_size" do
222
- let(:query_string) {%|
223
- query getBases($first: Int, $after: String, $last: Int, $before: String){
224
- federation {
225
- bases: basesWithMaxLimitRelation(first: $first, after: $after, last: $last, before: $before) {
226
- ... basesConnection
227
- }
228
- }
229
- }
230
-
231
- fragment basesConnection on BaseConnection {
232
- edges {
233
- cursor
234
- node {
235
- name
236
- }
237
- },
238
- pageInfo {
239
- hasNextPage
240
- hasPreviousPage
241
- startCursor
242
- endCursor
243
- }
244
- }
245
- |}
246
-
247
- it "applies to queries by `first`" do
248
- result = star_trek_query(query_string, "first" => 100)
249
- assert_equal(2, result["data"]["federation"]["bases"]["edges"].size)
250
- assert_equal(true, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"])
251
-
252
- # Max page size is applied _without_ `first`, also
253
- result = star_trek_query(query_string)
254
- assert_equal(2, result["data"]["federation"]["bases"]["edges"].size)
255
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
256
- end
257
-
258
- it "applies to queries by `last`" do
259
- second_to_last_two_names = ["Firebase P'ok", "Ganalda Space Station"]
260
- first_and_second_names = ["Deep Space Station K-7", "Regula I"]
261
-
262
- last_cursor = "Ng=="
263
- result = star_trek_query(query_string, "last" => 100, "before" => last_cursor)
264
- assert_equal(second_to_last_two_names, get_names(result))
265
- assert_equal(true, result["data"]["federation"]["bases"]["pageInfo"]["hasPreviousPage"])
266
-
267
- result = star_trek_query(query_string, "before" => last_cursor)
268
- assert_equal(first_and_second_names, get_names(result))
269
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasPreviousPage"], "hasPreviousPage is false when last is not specified")
270
-
271
- third_cursor = "Mw"
272
- result = star_trek_query(query_string, "last" => 100, "before" => third_cursor)
273
- assert_equal(first_and_second_names, get_names(result))
274
-
275
- result = star_trek_query(query_string, "before" => third_cursor)
276
- assert_equal(first_and_second_names, get_names(result))
277
- end
278
- end
279
-
280
- describe "applying default_max_page_size" do
281
- let(:query_string) {%|
282
- query getBases($first: Int, $after: String, $last: Int, $before: String){
283
- federation {
284
- bases: basesWithDefaultMaxLimitRelation(first: $first, after: $after, last: $last, before: $before) {
285
- ... basesConnection
286
- }
287
- }
288
- }
289
-
290
- fragment basesConnection on BaseConnection {
291
- edges {
292
- cursor
293
- node {
294
- name
295
- }
296
- },
297
- pageInfo {
298
- hasNextPage
299
- hasPreviousPage
300
- startCursor
301
- endCursor
302
- }
303
- }
304
- |}
305
-
306
- it "applies to queries by `first`" do
307
- result = star_trek_query(query_string, "first" => 100)
308
- assert_equal(3, result["data"]["federation"]["bases"]["edges"].size)
309
- assert_equal(true, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"])
310
-
311
- # Max page size is applied _without_ `first`, also
312
- result = star_trek_query(query_string)
313
- assert_equal(3, result["data"]["federation"]["bases"]["edges"].size)
314
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
315
- end
316
-
317
- it "applies to queries by `last`" do
318
- second_to_last_three_names = ["Deep Space Nine", "Firebase P'ok", "Ganalda Space Station"]
319
- first_second_and_third_names = ["Deep Space Station K-7", "Regula I", "Deep Space Nine"]
320
-
321
- last_cursor = "Ng=="
322
- result = star_trek_query(query_string, "last" => 100, "before" => last_cursor)
323
- assert_equal(second_to_last_three_names, get_names(result))
324
- assert_equal(true, result["data"]["federation"]["bases"]["pageInfo"]["hasPreviousPage"])
325
-
326
- result = star_trek_query(query_string, "before" => last_cursor)
327
- assert_equal(first_second_and_third_names, get_names(result))
328
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasPreviousPage"], "hasPreviousPage is false when last is not specified")
329
-
330
- fourth_cursor = "NA=="
331
- result = star_trek_query(query_string, "last" => 100, "before" => fourth_cursor)
332
- assert_equal(first_second_and_third_names, get_names(result))
333
-
334
- result = star_trek_query(query_string, "before" => fourth_cursor)
335
- assert_equal(first_second_and_third_names, get_names(result))
336
- end
337
- end
338
- end
339
-
340
- describe "applying a max_page_size bigger than the results" do
341
- let(:query_string) {%|
342
- query getBases($first: Int, $after: String, $last: Int, $before: String){
343
- federation {
344
- bases: basesWithLargeMaxLimitRelation(first: $first, after: $after, last: $last, before: $before) {
345
- ... basesConnection
346
- }
347
- }
348
- }
349
-
350
- fragment basesConnection on BaseConnection {
351
- edges {
352
- cursor
353
- node {
354
- name
355
- }
356
- },
357
- pageInfo {
358
- hasNextPage
359
- hasPreviousPage
360
- startCursor
361
- endCursor
362
- }
363
- }
364
- |}
365
-
366
- it "applies to queries by `first`" do
367
- result = star_trek_query(query_string, "first" => 100)
368
- assert_equal(6, result["data"]["federation"]["bases"]["edges"].size)
369
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"])
370
-
371
- # Max page size is applied _without_ `first`, also
372
- result = star_trek_query(query_string)
373
- assert_equal(6, result["data"]["federation"]["bases"]["edges"].size)
374
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
375
- end
376
-
377
- it "applies to queries by `last`" do
378
- all_names = ["Deep Space Station K-7", "Regula I", "Deep Space Nine", "Firebase P'ok", "Ganalda Space Station", "Rh'Ihho Station"]
379
-
380
- last_cursor = "Ng=="
381
- result = star_trek_query(query_string, "last" => 100, "before" => last_cursor)
382
- assert_equal(all_names[0..4], get_names(result))
383
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasPreviousPage"])
384
-
385
- result = star_trek_query(query_string, "last" => 100)
386
- assert_equal(all_names, get_names(result))
387
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasPreviousPage"])
388
-
389
- result = star_trek_query(query_string, "before" => last_cursor)
390
- assert_equal(all_names[0..4], get_names(result))
391
- assert_equal(false, result["data"]["federation"]["bases"]["pageInfo"]["hasPreviousPage"], "hasPreviousPage is false when last is not specified")
392
-
393
- fourth_cursor = "NA=="
394
- result = star_trek_query(query_string, "last" => 100, "before" => fourth_cursor)
395
- assert_equal(all_names[0..2], get_names(result))
396
-
397
- result = star_trek_query(query_string, "before" => fourth_cursor)
398
- assert_equal(all_names[0..2], get_names(result))
399
- end
400
- end
401
-
402
- describe "without a block" do
403
- let(:query_string) {%|
404
- {
405
- federation {
406
- basesClone(first: 10) {
407
- edges {
408
- node {
409
- name
410
- }
411
- }
412
- }
413
- }
414
- }|}
415
- it "uses default resolve" do
416
- result = star_trek_query(query_string)
417
- bases = result["data"]["federation"]["basesClone"]["edges"]
418
- assert_equal(3, bases.length)
419
- end
420
- end
421
-
422
- describe "custom ordering" do
423
- let(:query_string) {%|
424
- query getBases {
425
- federation {
426
- basesByName(first: 30) { ... basesFields }
427
- bases(first: 30) { ... basesFields2 }
428
- }
429
- }
430
- fragment basesFields on BaseConnection {
431
- edges {
432
- node {
433
- name
434
- }
435
- }
436
- }
437
- fragment basesFields2 on BasesConnectionWithTotalCount {
438
- edges {
439
- node {
440
- name
441
- }
442
- }
443
- }
444
- |}
445
-
446
- def get_names(result, field_name)
447
- bases = result["data"]["federation"][field_name]["edges"]
448
- bases.map { |b| b["node"]["name"] }
449
- end
450
-
451
- it "applies the default value" do
452
- result = star_trek_query(query_string)
453
- bases_by_id = ["Deep Space Station K-7", "Regula I", "Deep Space Nine"]
454
- bases_by_name = ["Deep Space Nine", "Deep Space Station K-7", "Regula I"]
455
-
456
- assert_equal(bases_by_id, get_names(result, "bases"))
457
- assert_equal(bases_by_name, get_names(result, "basesByName"))
458
- end
459
- end
460
-
461
- describe "#cursor_from_node" do
462
- let(:connection) { GraphQL::Relay::MongoRelationConnection.new(StarTrek::Base.where(faction_id: 1), {}) }
463
-
464
- it "returns the cursor for a node in the connection" do
465
- assert_equal "MQ", connection.cursor_from_node(StarTrek::Base.all[0])
466
- assert_equal "Mg", connection.cursor_from_node(StarTrek::Base.all[1])
467
- end
468
-
469
- it "raises when the node isn't found" do
470
- err = assert_raises(RuntimeError) {
471
- connection.cursor_from_node(:not_found)
472
- }
473
- assert_includes err.message, "item not found"
474
- end
475
- end
476
-
477
- it "is chosen for a relation" do
478
- relation = StarTrek::Base.where(faction_id: 1)
479
- assert relation.is_a?(Mongoid::Criteria)
480
- connection = GraphQL::Relay::BaseConnection.connection_for_nodes(relation)
481
- assert_equal GraphQL::Relay::MongoRelationConnection, connection
482
- end
483
-
484
- describe "relations" do
485
- let(:query_string) {%|
486
- query getShips {
487
- federation {
488
- bases {
489
- ... basesConnection
490
- }
491
- }
492
- }
493
-
494
- fragment basesConnection on BasesConnectionWithTotalCount {
495
- edges {
496
- cursor
497
- node {
498
- name
499
- residents {
500
- edges {
501
- node {
502
- name
503
- }
504
- }
505
- }
506
- }
507
- }
508
- }
509
- |}
510
-
511
- it "Mongoid::Association::Referenced::HasMany::Targets::Enumerable" do
512
- result = star_trek_query(query_string)
513
- assert_equal get_ships_residents(result), {
514
- "Deep Space Station K-7" => [
515
- "Shir th'Talias",
516
- "Lurry",
517
- "Mackenzie Calhoun"
518
- ],
519
- "Regula I" => [
520
- "V. Madison",
521
- "D. March",
522
- "C. Marcus"
523
- ],
524
- "Deep Space Nine" => []
525
- }
526
- end
527
- end
528
- end