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,2 +0,0 @@
1
- # frozen_string_literal: true
2
- require "mongoid" if RUBY_ENGINE == 'ruby'
@@ -1,126 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'ostruct'
3
-
4
- module StarTrek
5
- names = [
6
- 'USS Enterprise',
7
- 'USS Excelsior',
8
- 'USS Reliant',
9
- 'IKS Koraga',
10
- 'IKS Kronos One',
11
- 'IRW Khazara',
12
- 'IRW Praetus',
13
- ]
14
-
15
- MONGOID_CONFIG = {
16
- clients: {
17
- default: {
18
- database: 'graphql_ruby_test',
19
- hosts: ['localhost:27017']
20
- }
21
- },
22
- sessions: {
23
- default: {
24
- database: 'graphql_ruby_test',
25
- hosts: ['localhost:27017']
26
- }
27
- }
28
- }.freeze
29
-
30
- def db_name
31
- MONGOID_CONFIG[:clients][:default][:database]
32
- end
33
- module_function :db_name
34
-
35
- # Set up "Bases" in MongoDB
36
- Mongoid.load_configuration(MONGOID_CONFIG)
37
-
38
- class Base
39
- include Mongoid::Document
40
- field :name, type: String
41
- field :sector, type: String
42
- field :faction_id, type: Integer
43
- has_many :residents, class_name: 'StarTrek::Resident', inverse_of: :base
44
- end
45
-
46
- class Resident
47
- include Mongoid::Document
48
- field :name, type: String
49
- belongs_to :base, class_name: 'StarTrek::Base'
50
- end
51
-
52
- Base.collection.drop
53
-
54
- dsk7 = Base.create!(name: "Deep Space Station K-7", sector: "Mempa", faction_id: 1)
55
- dsk7.residents.create!(name: "Shir th'Talias")
56
- dsk7.residents.create!(name: "Lurry")
57
- dsk7.residents.create!(name: "Mackenzie Calhoun")
58
-
59
- r1 = Base.create!(name: "Regula I", sector: "Mutara", faction_id: 1)
60
- r1.residents.create!(name: "V. Madison")
61
- r1.residents.create!(name: "D. March")
62
- r1.residents.create!(name: "C. Marcus")
63
-
64
- Base.create!(name: "Deep Space Nine", sector: "Bajoran", faction_id: 1)
65
- Base.create!(name: "Firebase P'ok", sector: nil, faction_id: 2)
66
- Base.create!(name: "Ganalda Space Station", sector: "Archanis", faction_id: 2)
67
- Base.create!(name: "Rh'Ihho Station", sector: "Rator", faction_id: 3)
68
-
69
-
70
- class FactionRecord
71
- attr_reader :id, :name, :ships, :bases, :bases_clone
72
- def initialize(id:, name:, ships:, bases:, bases_clone:)
73
- @id = id
74
- @name = name
75
- @ships = ships
76
- @bases = bases
77
- @bases_clone = bases_clone
78
- end
79
- end
80
-
81
- federation = FactionRecord.new({
82
- id: '1',
83
- name: 'United Federation of Planets',
84
- ships: ['1', '2', '3'],
85
- bases: Base.where(faction_id: 1),
86
- bases_clone: Base.where(faction_id: 1),
87
- })
88
-
89
- klingon = FactionRecord.new({
90
- id: '2',
91
- name: 'Klingon Empire',
92
- ships: ['4', '5'],
93
- bases: Base.where(faction_id: 2),
94
- bases_clone: Base.where(faction_id: 2),
95
- })
96
-
97
- romulan = FactionRecord.new({
98
- id: '2',
99
- name: 'Romulan Star Empire',
100
- ships: ['6', '7'],
101
- bases: Base.where(faction_id: 3),
102
- bases_clone: Base.where(faction_id: 3),
103
- })
104
-
105
- DATA = {
106
- "Faction" => {
107
- "1" => federation,
108
- "2" => klingon,
109
- "3" => romulan,
110
- },
111
- "Ship" => names.each_with_index.reduce({}) do |memo, (name, idx)|
112
- id = (idx + 1).to_s
113
- memo[id] = OpenStruct.new(name: name, id: id)
114
- memo
115
- end,
116
- "Base" => Hash.new { |h, k| h[k] = Base.find(k) }
117
- }
118
-
119
- def DATA.create_ship(name, faction_id)
120
- new_id = (self["Ship"].keys.map(&:to_i).max + 1).to_s
121
- new_ship = OpenStruct.new(id: new_id, name: name)
122
- self["Ship"][new_id] = new_ship
123
- self["Faction"][faction_id].ships << new_id
124
- new_ship
125
- end
126
- end
@@ -1,424 +0,0 @@
1
- # frozen_string_literal: true
2
- module StarTrek
3
- # Adapted from graphql-relay-js
4
- # https://github.com/graphql/graphql-relay-js/blob/master/src/__tests__/StarTrekSchema.js
5
-
6
- class Ship < GraphQL::Schema::Object
7
- implements GraphQL::Relay::Node.interface
8
- global_id_field :id
9
- field :name, String, null: true
10
- # Test cyclical connection types:
11
- field :ships, Ship.connection_type, null: false
12
- end
13
-
14
- class ResidentType < GraphQL::Schema::Object
15
- global_id_field :id
16
- field :name, String, null: true
17
- end
18
-
19
- class BaseType < GraphQL::Schema::Object
20
- graphql_name "Base"
21
- implements GraphQL::Relay::Node.interface
22
- global_id_field :id
23
- field :name, String, null: false, resolve: ->(obj, args, ctx) {
24
- LazyWrapper.new {
25
- if obj.id.nil?
26
- raise GraphQL::ExecutionError, "Boom!"
27
- else
28
- obj.name
29
- end
30
- }
31
- }
32
- field :sector, String, null: true
33
- field :residents, ResidentType.connection_type, null: true
34
- end
35
-
36
- class BaseConnectionWithTotalCountType < GraphQL::Types::Relay::BaseConnection
37
- graphql_name "BasesConnectionWithTotalCount"
38
- edge_type(BaseType.edge_type)
39
- field :total_count, Integer, null: true
40
-
41
- def total_count
42
- object.nodes.count
43
- end
44
- end
45
-
46
- class CustomBaseEdge < GraphQL::Relay::Edge
47
- def upcased_name
48
- node.name.upcase
49
- end
50
-
51
- def upcased_parent_name
52
- parent.name.upcase
53
- end
54
- end
55
-
56
- class CustomBaseEdgeType < GraphQL::Types::Relay::BaseEdge
57
- node_type(BaseType)
58
- field :upcased_name, String, null: true
59
- field :upcased_parent_name, String, null: true
60
- field :edge_class_name, String, null: true
61
-
62
- def edge_class_name
63
- object.class.name
64
- end
65
- end
66
-
67
- class CustomEdgeBaseConnectionType < GraphQL::Types::Relay::BaseConnection
68
- edge_type(CustomBaseEdgeType, edge_class: CustomBaseEdge)
69
-
70
- field :total_count_times_100, Integer, null: true
71
- def total_count_times_100
72
- obj.nodes.count * 100
73
- end
74
-
75
- field :field_name, String, null: true
76
- def field_name
77
- object.field.name
78
- end
79
- end
80
-
81
-
82
- class ShipsWithMaxPageSize < GraphQL::Schema::Resolver
83
- argument :name_includes, String, required: false
84
- type Ship.connection_type, null: true
85
-
86
- def resolve(name_includes: nil)
87
- all_ships = object.ships.map { |ship_id| StarTrek::DATA["Ship"][ship_id] }
88
- if name_includes
89
- all_ships = all_ships.select { |ship| ship.name.include?(name_includes)}
90
- end
91
- all_ships
92
- end
93
- end
94
-
95
- class ShipConnectionWithParentType < GraphQL::Types::Relay::BaseConnection
96
- edge_type(Ship.edge_type)
97
- graphql_name "ShipConnectionWithParent"
98
- field :parent_class_name, String, null: false
99
- def parent_class_name
100
- object.parent.class.name
101
- end
102
- end
103
-
104
- class Faction < GraphQL::Schema::Object
105
- implements GraphQL::Relay::Node.interface
106
-
107
- field :id, ID, null: false, resolve: GraphQL::Relay::GlobalIdResolve.new(type: Faction)
108
- field :name, String, null: true
109
- field :ships, ShipConnectionWithParentType, connection: true, max_page_size: 1000, null: true do
110
- argument :name_includes, String, required: false
111
- end
112
-
113
- def ships(name_includes: nil)
114
- all_ships = object.ships.map {|ship_id| StarTrek::DATA["Ship"][ship_id] }
115
- if name_includes
116
- case name_includes
117
- when "error"
118
- all_ships = GraphQL::ExecutionError.new("error from within connection")
119
- when "raisedError"
120
- raise GraphQL::ExecutionError.new("error raised from within connection")
121
- when "lazyError"
122
- all_ships = LazyWrapper.new { GraphQL::ExecutionError.new("lazy error from within connection") }
123
- when "lazyRaisedError"
124
- all_ships = LazyWrapper.new { raise GraphQL::ExecutionError.new("lazy raised error from within connection") }
125
- when "null"
126
- all_ships = nil
127
- when "lazyObject"
128
- prev_all_ships = all_ships
129
- all_ships = LazyWrapper.new { prev_all_ships }
130
- else
131
- all_ships = all_ships.select { |ship| ship.name.include?(name_includes)}
132
- end
133
- end
134
- all_ships
135
- end
136
-
137
- field :shipsWithMaxPageSize, "Ships with max page size", max_page_size: 2, resolver: ShipsWithMaxPageSize
138
-
139
- field :bases, BaseConnectionWithTotalCountType, null: true, connection: true do
140
- argument :name_includes, String, required: false
141
- end
142
-
143
- def bases(name_includes: nil)
144
- all_bases = object.bases
145
- if name_includes
146
- all_bases = all_bases.where(name: Regexp.new(name_includes))
147
- end
148
- all_bases
149
- end
150
-
151
- field :basesClone, BaseType.connection_type, null: true
152
- field :basesByName, BaseType.connection_type, null: true do
153
- argument :order, String, default_value: "name", required: false
154
- end
155
- def bases_by_name(order: nil)
156
- if order.present?
157
- @object.bases.order_by(name: order)
158
- else
159
- @object.bases
160
- end
161
- end
162
-
163
- def all_bases
164
- Base.all
165
- end
166
-
167
- def all_bases_array
168
- all_bases.to_a
169
- end
170
-
171
- field :basesWithMaxLimitRelation, BaseType.connection_type, null: true, max_page_size: 2, resolver_method: :all_bases
172
- field :basesWithMaxLimitArray, BaseType.connection_type, null: true, max_page_size: 2, resolver_method: :all_bases_array
173
- field :basesWithDefaultMaxLimitRelation, BaseType.connection_type, null: true, resolver_method: :all_bases
174
- field :basesWithDefaultMaxLimitArray, BaseType.connection_type, null: true, resolver_method: :all_bases_array
175
- field :basesWithLargeMaxLimitRelation, BaseType.connection_type, null: true, max_page_size: 1000, resolver_method: :all_bases
176
-
177
- field :basesWithCustomEdge, CustomEdgeBaseConnectionType, null: true, connection: true
178
- def bases_with_custom_edge
179
- LazyNodesWrapper.new(object.bases)
180
- end
181
- end
182
-
183
- class IntroduceShipMutation < GraphQL::Schema::RelayClassicMutation
184
- description "Add a ship to this faction"
185
-
186
- # Nested under `input` in the query:
187
- argument :ship_name, String, required: false
188
- argument :faction_id, ID, required: true
189
-
190
- # Result may have access to these fields:
191
- field :ship_edge, Ship.edge_type, null: true
192
- field :faction, Faction, null: true
193
- field :aliased_faction, Faction, hash_key: :aliased_faction, null: true
194
-
195
- def resolve(ship_name: nil, faction_id:)
196
- IntroduceShipFunction.new.call(object, {ship_name: ship_name, faction_id: faction_id}, context)
197
- end
198
- end
199
-
200
- class IntroduceShipFunction < GraphQL::Function
201
- description "Add a ship to this faction"
202
-
203
- argument :shipName, GraphQL::STRING_TYPE
204
- argument :factionId, !GraphQL::ID_TYPE
205
-
206
- type(GraphQL::ObjectType.define do
207
- name "IntroduceShipFunctionPayload"
208
- field :shipEdge, Ship.edge_type, hash_key: :shipEdge
209
- field :faction, Faction, hash_key: :shipEdge
210
- end)
211
-
212
- def call(obj, args, ctx)
213
- # support old and new args
214
- ship_name = args["shipName"] || args[:ship_name]
215
- faction_id = args["factionId"] || args[:faction_id]
216
- if ship_name == 'USS Voyager'
217
- GraphQL::ExecutionError.new("Sorry, USS Voyager ship is reserved")
218
- elsif ship_name == 'IKS Korinar'
219
- raise GraphQL::ExecutionError.new("🔥")
220
- elsif ship_name == 'Scimitar'
221
- LazyWrapper.new { raise GraphQL::ExecutionError.new("💥")}
222
- else
223
- ship = DATA.create_ship(ship_name, faction_id)
224
- faction = DATA["Faction"][faction_id]
225
- connection_class = GraphQL::Relay::BaseConnection.connection_for_nodes(faction.ships)
226
- ships_connection = connection_class.new(faction.ships, args)
227
- ship_edge = GraphQL::Relay::Edge.new(ship, ships_connection)
228
- result = {
229
- shipEdge: ship_edge,
230
- ship_edge: ship_edge, # support new-style, too
231
- faction: faction,
232
- aliased_faction: faction,
233
- }
234
- if args["shipName"] == "Slave II"
235
- LazyWrapper.new(result)
236
- else
237
- result
238
- end
239
- end
240
- end
241
- end
242
-
243
- IntroduceShipFunctionMutation = GraphQL::Relay::Mutation.define do
244
- # Used as the root for derived types:
245
- name "IntroduceShipFunction"
246
- function IntroduceShipFunction.new
247
- end
248
-
249
- # GraphQL-Batch knockoff
250
- class LazyLoader
251
- def self.defer(ctx, model, id)
252
- ids = ctx.namespace(:loading)[model] ||= []
253
- ids << id
254
- self.new(model: model, id: id, context: ctx)
255
- end
256
-
257
- def initialize(model:, id:, context:)
258
- @model = model
259
- @id = id
260
- @context = context
261
- end
262
-
263
- def value
264
- loaded = @context.namespace(:loaded)[@model] ||= {}
265
- if loaded.empty?
266
- ids = @context.namespace(:loading)[@model]
267
- # Example custom tracing
268
- @context.trace("lazy_loader", { ids: ids, model: @model}) do
269
- records = @model.where(id: ids)
270
- records.each do |record|
271
- loaded[record.id.to_s] = record
272
- end
273
- end
274
- end
275
-
276
- loaded[@id]
277
- end
278
- end
279
-
280
- class LazyWrapper
281
- def initialize(value = nil, &block)
282
- if block_given?
283
- @lazy_value = block
284
- else
285
- @value = value
286
- end
287
- end
288
-
289
- def value
290
- @resolved_value = @value || @lazy_value.call
291
- end
292
- end
293
-
294
- LazyNodesWrapper = Struct.new(:relation)
295
- class LazyNodesRelationConnection < GraphQL::Relay::RelationConnection
296
- def initialize(wrapper, *args)
297
- super(wrapper.relation, *args)
298
- end
299
-
300
- def edge_nodes
301
- LazyWrapper.new { super }
302
- end
303
- end
304
-
305
- GraphQL::Relay::BaseConnection.register_connection_implementation(LazyNodesWrapper, LazyNodesRelationConnection)
306
-
307
- class QueryType < GraphQL::Schema::Object
308
- graphql_name "Query"
309
-
310
- field :federation, Faction, null: true, resolve: ->(obj, args, ctx) { StarTrek::DATA["Faction"]["1"]}
311
-
312
- field :klingons, Faction, null: true, resolve: ->(obj, args, ctx) { StarTrek::DATA["Faction"]["2"]}
313
-
314
- field :romulans, Faction, null: true, resolve: ->(obj, args, ctx) { StarTrek::DATA["Faction"]["3"]}
315
-
316
- field :largestBase, BaseType, null: true, resolve: ->(obj, args, ctx) { Base.find(3) }
317
-
318
- field :newestBasesGroupedByFaction, BaseType.connection_type, null: true
319
-
320
- def newest_bases_grouped_by_faction
321
- agg = Base.collection.aggregate([{
322
- "$group" => {
323
- "_id" => "$faction_id",
324
- "baseId" => { "$max" => "$_id" }
325
- }
326
- }])
327
- Base.
328
- in(id: agg.map { |doc| doc['baseId'] }).
329
- order_by(faction_id: -1)
330
- end
331
-
332
- field :basesWithNullName, BaseType.connection_type, null: false
333
-
334
- def bases_with_null_name
335
- [OpenStruct.new(id: nil)]
336
- end
337
-
338
- field :node, field: GraphQL::Relay::Node.field
339
-
340
- custom_node_field = GraphQL::Relay::Node.field do
341
- resolve ->(_, _, _) { StarTrek::DATA["Faction"]["1"] }
342
- end
343
- field :nodeWithCustomResolver, field: custom_node_field
344
-
345
- field :nodes, field: GraphQL::Relay::Node.plural_field
346
- field :nodesWithCustomResolver, field: GraphQL::Relay::Node.plural_field(
347
- resolve: ->(_, _, _) { [StarTrek::DATA["Faction"]["1"], StarTrek::DATA["Faction"]["2"]] }
348
- )
349
-
350
- field :batchedBase, BaseType, null: true do
351
- argument :id, ID, required: true
352
- end
353
-
354
- def batched_base(id:)
355
- LazyLoader.defer(@context, Base, id)
356
- end
357
- end
358
-
359
- class MutationType < GraphQL::Schema::Object
360
- graphql_name "Mutation"
361
- field :introduceShip, mutation: IntroduceShipMutation
362
- # To hook up a Relay::Mutation
363
- field :introduceShipFunction, field: IntroduceShipFunctionMutation.field
364
- end
365
-
366
- class ClassNameRecorder
367
- def initialize(context_key)
368
- @context_key = context_key
369
- end
370
-
371
- def instrument(type, field)
372
- inner_resolve = field.resolve_proc
373
- key = @context_key
374
- field.redefine {
375
- resolve ->(o, a, c) {
376
- res = inner_resolve.call(o, a, c)
377
- if c[key]
378
- c[key] << res.class.name
379
- end
380
- res
381
- }
382
- }
383
- end
384
- end
385
-
386
- class Schema < GraphQL::Schema
387
- query(QueryType)
388
- mutation(MutationType)
389
- default_max_page_size 3
390
-
391
- if TESTING_INTERPRETER
392
- use GraphQL::Execution::Interpreter
393
- end
394
-
395
- def self.resolve_type(type, object, ctx)
396
- if object == :test_error
397
- :not_a_type
398
- elsif object.is_a?(Base)
399
- BaseType
400
- elsif DATA["Faction"].values.include?(object)
401
- Faction
402
- elsif DATA["Ship"].values.include?(object)
403
- Ship
404
- else
405
- nil
406
- end
407
- end
408
-
409
- def self.object_from_id(node_id, ctx)
410
- type_name, id = GraphQL::Schema::UniqueWithinType.decode(node_id)
411
- StarTrek::DATA[type_name][id]
412
- end
413
-
414
- def self.id_from_object(object, type, ctx)
415
- GraphQL::Schema::UniqueWithinType.encode(type.graphql_name, object.id)
416
- end
417
-
418
- lazy_resolve(LazyWrapper, :value)
419
- lazy_resolve(LazyLoader, :value)
420
-
421
- instrument(:field, ClassNameRecorder.new(:before_built_ins))
422
- instrument(:field, ClassNameRecorder.new(:after_built_ins), after_built_ins: true)
423
- end
424
- end