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,192 +0,0 @@
1
- # frozen_string_literal: true
2
- module LazyHelpers
3
- MAGIC_NUMBER_WITH_LAZY_AUTHORIZED_HOOK = 44
4
- MAGIC_NUMBER_THAT_RETURNS_NIL = 0
5
- MAGIC_NUMBER_THAT_RAISES_ERROR = 13
6
- class Wrapper
7
- def initialize(item = nil, &block)
8
- if block
9
- @block = block
10
- else
11
- @item = item
12
- end
13
- end
14
-
15
- def item
16
- if @block
17
- @item = @block.call()
18
- @block = nil
19
- end
20
- @item
21
- end
22
- end
23
-
24
- class SumAll
25
- attr_reader :own_value
26
- attr_writer :value
27
-
28
- def initialize(own_value)
29
- @own_value = own_value
30
- all << self
31
- end
32
-
33
- def value
34
- @value ||= begin
35
- total_value = all.map(&:own_value).reduce(&:+)
36
- all.each { |v| v.value = total_value}
37
- all.clear
38
- total_value
39
- end
40
- @value
41
- end
42
-
43
- def all
44
- self.class.all
45
- end
46
-
47
- def self.all
48
- @all ||= []
49
- end
50
- end
51
-
52
- class LazySum < GraphQL::Schema::Object
53
- field :value, Integer, null: true
54
- def value
55
- if object == MAGIC_NUMBER_THAT_RAISES_ERROR
56
- nil
57
- else
58
- object
59
- end
60
- end
61
-
62
- def self.authorized?(obj, ctx)
63
- if obj == MAGIC_NUMBER_WITH_LAZY_AUTHORIZED_HOOK
64
- Wrapper.new { true }
65
- else
66
- true
67
- end
68
- end
69
-
70
- field :nestedSum, LazySum, null: false do
71
- argument :value, Integer, required: true
72
- end
73
-
74
- def nested_sum(value:)
75
- if value == MAGIC_NUMBER_THAT_RAISES_ERROR
76
- Wrapper.new(nil)
77
- else
78
- SumAll.new(@object + value)
79
- end
80
- end
81
-
82
- field :nullableNestedSum, LazySum, null: true do
83
- argument :value, Integer, required: true
84
- end
85
- alias :nullable_nested_sum :nested_sum
86
- end
87
-
88
- using GraphQL::DeprecatedDSL
89
- if RUBY_ENGINE == "jruby"
90
- # JRuby doesn't support refinements, so the `using` above won't work
91
- GraphQL::DeprecatedDSL.activate
92
- end
93
-
94
- class LazyQuery < GraphQL::Schema::Object
95
- field :int, Integer, null: false do
96
- argument :value, Integer, required: true
97
- argument :plus, Integer, required: false, default_value: 0
98
- end
99
- def int(value:, plus:)
100
- Wrapper.new(value + plus)
101
- end
102
-
103
- field :nested_sum, LazySum, null: false do
104
- argument :value, Integer, required: true
105
- end
106
-
107
- def nested_sum(value:)
108
- SumAll.new(value)
109
- end
110
-
111
- field :nullable_nested_sum, LazySum, null: true do
112
- argument :value, Integer, required: true
113
- end
114
-
115
- def nullable_nested_sum(value:)
116
- if value == MAGIC_NUMBER_THAT_RAISES_ERROR
117
- Wrapper.new { raise GraphQL::ExecutionError.new("#{MAGIC_NUMBER_THAT_RAISES_ERROR} is unlucky") }
118
- elsif value == MAGIC_NUMBER_THAT_RETURNS_NIL
119
- nil
120
- else
121
- SumAll.new(value)
122
- end
123
- end
124
-
125
- field :list_sum, [LazySum, null: true], null: true do
126
- argument :values, [Integer], required: true, method_access: false
127
- end
128
- def list_sum(values:)
129
- values.map { |v| v == MAGIC_NUMBER_THAT_RETURNS_NIL ? nil : v }
130
- end
131
- end
132
-
133
- class SumAllInstrumentation
134
- def initialize(counter:)
135
- @counter = counter
136
- end
137
-
138
- def before_query(q)
139
- add_check(q, "before #{q.selected_operation.name}")
140
- # TODO not threadsafe
141
- # This should use multiplex-level context
142
- SumAll.all.clear
143
- end
144
-
145
- def after_query(q)
146
- add_check(q, "after #{q.selected_operation.name}")
147
- end
148
-
149
- def before_multiplex(multiplex)
150
- add_check(multiplex, "before multiplex #@counter")
151
- end
152
-
153
- def after_multiplex(multiplex)
154
- add_check(multiplex, "after multiplex #@counter")
155
- end
156
-
157
- def add_check(obj, text)
158
- checks = obj.context[:instrumentation_checks]
159
- if checks
160
- checks << text
161
- end
162
- end
163
- end
164
-
165
- class LazySchema < GraphQL::Schema
166
- query(LazyQuery)
167
- mutation(LazyQuery)
168
- lazy_resolve(Wrapper, :item)
169
- lazy_resolve(SumAll, :value)
170
- instrument(:query, SumAllInstrumentation.new(counter: nil))
171
- instrument(:multiplex, SumAllInstrumentation.new(counter: 1))
172
- instrument(:multiplex, SumAllInstrumentation.new(counter: 2))
173
-
174
- if TESTING_INTERPRETER
175
- use GraphQL::Execution::Interpreter
176
- use GraphQL::Analysis::AST
177
- end
178
-
179
- def self.sync_lazy(lazy)
180
- if lazy.is_a?(SumAll) && lazy.own_value > 1000
181
- lazy.value # clear the previous set
182
- lazy.own_value - 900
183
- else
184
- super
185
- end
186
- end
187
- end
188
-
189
- def run_query(query_str, **rest)
190
- LazySchema.execute(query_str, **rest)
191
- end
192
- end
@@ -1,33 +0,0 @@
1
- type Card {
2
- name: String!
3
- printings: [Printing!]!
4
- expansions: [Expansion!]!
5
- colors: [Color!]!
6
- convertedManaCost: Int!
7
- }
8
-
9
- type Expansion {
10
- name: String!
11
- symbol: String!
12
- printings: [Printing!]!
13
- cards: [Card!]!
14
- }
15
-
16
- type Printing {
17
- card: Card!
18
- expansion: Expansion!
19
- }
20
-
21
- enum Color {
22
- RED
23
- GREEN
24
- BLACK
25
- BLUE
26
- WHITE
27
- COLORLESS
28
- }
29
-
30
- type Query {
31
- card(name: String!): Card
32
- expansion(symbol: String!): Expansion
33
- }
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
- # This is the minimum required interface for an input object
3
- class MinimumInputObject
4
- include Enumerable
5
-
6
- def initialize(values)
7
- @values = values
8
- end
9
-
10
- def each(&block)
11
- @values.each(&block)
12
- end
13
-
14
- def [](key)
15
- @values[key]
16
- end
17
-
18
- def key?(key)
19
- @values.key?(key)
20
- end
21
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
- # A stub for the NewRelic agent, so we can make assertions about how it is used
3
- if defined?(NewRelic)
4
- raise "Expected NewRelic to be undefined, so that we could define a stub for it."
5
- end
6
-
7
- module NewRelic
8
- TRANSACTION_NAMES = []
9
- EXECUTION_SCOPES = []
10
- # Reset state between tests
11
- def self.clear_all
12
- TRANSACTION_NAMES.clear
13
- EXECUTION_SCOPES.clear
14
- end
15
- module Agent
16
- def self.set_transaction_name(name)
17
- TRANSACTION_NAMES << name
18
- end
19
-
20
- module MethodTracerHelpers
21
- def self.trace_execution_scoped(trace_name)
22
- EXECUTION_SCOPES << trace_name
23
- yield
24
- end
25
- end
26
- end
27
- end
@@ -1,5 +0,0 @@
1
- {
2
- node(id: 1) {
3
- stuff
4
- }
5
- }
@@ -1,4 +0,0 @@
1
- {
2
- node(id: 2) {
3
- stuff
4
- }
@@ -1,5 +0,0 @@
1
- {
2
- node(id: 2) {
3
- stuff "str"
4
- }
5
- }
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
- # A stub for the Skylight agent, so we can make assertions about how it is used
3
- # Based on:
4
- # - https://www.rubydoc.info/gems/skylight-core/2.0.2
5
- # - https://www.rubydoc.info/gems/skylight/2.0.2
6
- if defined?(Skylight)
7
- raise "Expected Skylight to be undefined, so that we could define a stub for it."
8
- end
9
-
10
- module Skylight
11
- ENDPOINT_NAMES = []
12
- TITLE_NAMES = []
13
- # Reset state between tests
14
- def self.clear_all
15
- ENDPOINT_NAMES.clear
16
- TITLE_NAMES.clear
17
- end
18
-
19
- def self.instrumenter
20
- Instrumenter
21
- end
22
-
23
- def self.instrument(category:, title:)
24
- TITLE_NAMES << title
25
- yield
26
- end
27
-
28
- module Instrumenter
29
- def self.current_trace
30
- CurrentTrace
31
- end
32
- end
33
-
34
- module CurrentTrace
35
- def self.endpoint=(endpoint)
36
- ENDPOINT_NAMES << endpoint
37
- end
38
- end
39
- end
@@ -1,464 +0,0 @@
1
- # frozen_string_literal: true
2
- module StarWars
3
- # Adapted from graphql-relay-js
4
- # https://github.com/graphql/graphql-relay-js/blob/master/src/__tests__/starWarsSchema.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 BaseType < GraphQL::Schema::Object
15
- graphql_name "Base"
16
- implements GraphQL::Relay::Node.interface
17
- global_id_field :id
18
- field :name, String, null: false
19
- def name
20
- LazyWrapper.new {
21
- if object.id.nil?
22
- raise GraphQL::ExecutionError, "Boom!"
23
- else
24
- object.name
25
- end
26
- }
27
- end
28
- field :planet, String, null: true
29
- end
30
-
31
-
32
- class BaseEdge < GraphQL::Types::Relay::BaseEdge
33
- node_type(BaseType)
34
- end
35
-
36
- class BaseConnection < GraphQL::Types::Relay::BaseConnection
37
- edge_type(BaseEdge)
38
- end
39
-
40
- class BaseConnectionWithoutNodes < GraphQL::Types::Relay::BaseConnection
41
- edge_type(BaseEdge, nodes_field: false)
42
- end
43
-
44
- class BasesConnectionWithTotalCountType < GraphQL::Types::Relay::BaseConnection
45
- edge_type(BaseEdge, nodes_field: false)
46
- nodes_field
47
-
48
- field :total_count, Integer, null: true
49
-
50
- def total_count
51
- object.nodes.count
52
- end
53
- end
54
-
55
- class CustomBaseEdge < GraphQL::Relay::Edge
56
- def upcased_name
57
- node.name.upcase
58
- end
59
-
60
- def upcased_parent_name
61
- parent.name.upcase
62
- end
63
- end
64
-
65
- class CustomBaseEdgeType < GraphQL::Types::Relay::BaseEdge
66
- node_type(BaseType)
67
- field :upcased_name, String, null: true
68
- field :upcased_parent_name, String, null: true
69
- field :edge_class_name, String, null: true
70
-
71
- def edge_class_name
72
- object.class.name
73
- end
74
- end
75
-
76
- class CustomEdgeBaseConnectionType < GraphQL::Types::Relay::BaseConnection
77
- edge_type(CustomBaseEdgeType, edge_class: CustomBaseEdge, nodes_field: true)
78
- field :total_count_times_100, Integer, null: true
79
- def total_count_times_100
80
- object.nodes.count * 100
81
- end
82
-
83
- field :field_name, String, null: true
84
- def field_name
85
- object.field.name
86
- end
87
- end
88
-
89
- class ShipsWithMaxPageSize < GraphQL::Schema::Resolver
90
- argument :name_includes, String, required: false
91
- type Ship.connection_type, null: true
92
-
93
- def resolve(name_includes: nil)
94
- all_ships = object.ships.map { |ship_id| StarWars::DATA["Ship"][ship_id] }
95
- if name_includes
96
- all_ships = all_ships.select { |ship| ship.name.include?(name_includes)}
97
- end
98
- all_ships
99
- end
100
- end
101
-
102
- class ShipConnectionWithParentType < GraphQL::Types::Relay::BaseConnection
103
- edge_type(Ship.edge_type)
104
- field :parent_class_name, String, null: false
105
-
106
- def parent_class_name
107
- object.parent.class.name
108
- end
109
- end
110
-
111
- class ShipsByResolver < GraphQL::Schema::Resolver
112
- type ShipConnectionWithParentType, null: false
113
-
114
- def resolve
115
- object.ships.map { |ship_id| StarWars::DATA["Ship"][ship_id] }
116
- end
117
- end
118
-
119
- class Faction < GraphQL::Schema::Object
120
- implements GraphQL::Relay::Node.interface
121
-
122
- field :id, ID, null: false
123
- def id
124
- GraphQL::Relay::GlobalIdResolve.new(type: Faction).call(object, {}, context)
125
- end
126
-
127
- field :name, String, null: true
128
- field :ships, ShipConnectionWithParentType, connection: true, max_page_size: 1000, null: true do
129
- argument :name_includes, String, required: false
130
- end
131
-
132
- field :shipsByResolver, resolver: ShipsByResolver, connection: true
133
-
134
- def ships(name_includes: nil)
135
- all_ships = object.ships.map {|ship_id| StarWars::DATA["Ship"][ship_id] }
136
- if name_includes
137
- case name_includes
138
- when "error"
139
- all_ships = GraphQL::ExecutionError.new("error from within connection")
140
- when "raisedError"
141
- raise GraphQL::ExecutionError.new("error raised from within connection")
142
- when "lazyError"
143
- all_ships = LazyWrapper.new { GraphQL::ExecutionError.new("lazy error from within connection") }
144
- when "lazyRaisedError"
145
- all_ships = LazyWrapper.new { raise GraphQL::ExecutionError.new("lazy raised error from within connection") }
146
- when "null"
147
- all_ships = nil
148
- when "lazyObject"
149
- prev_all_ships = all_ships
150
- all_ships = LazyWrapper.new { prev_all_ships }
151
- else
152
- all_ships = all_ships.select { |ship| ship.name.include?(name_includes)}
153
- end
154
- end
155
- all_ships
156
- end
157
-
158
- field :shipsWithMaxPageSize, "Ships with max page size", max_page_size: 2, resolver: ShipsWithMaxPageSize
159
-
160
- field :bases, BasesConnectionWithTotalCountType, null: true, connection: true do
161
- argument :nameIncludes, String, required: false
162
- argument :complexOrder, Boolean, required: false
163
- end
164
-
165
- def bases(name_includes: nil, complex_order: nil)
166
- all_bases = Base.where(id: object.bases)
167
- if name_includes
168
- all_bases = all_bases.where("name LIKE ?", "%#{name_includes}%")
169
- end
170
- if complex_order
171
- all_bases = all_bases.order("bases.name DESC")
172
- end
173
- all_bases
174
- end
175
-
176
- field :basesClone, BaseConnection, null: true
177
- field :basesByName, BaseConnection, null: true do
178
- argument :order, String, default_value: "name", required: false
179
- end
180
- def bases_by_name(order: nil)
181
- if order.present?
182
- @object.bases.order(order)
183
- else
184
- @object.bases
185
- end
186
- end
187
-
188
- def all_bases
189
- Base.all
190
- end
191
-
192
- def all_bases_array
193
- all_bases.to_a
194
- end
195
-
196
- field :basesWithMaxLimitRelation, BaseConnection, null: true, max_page_size: 2, resolver_method: :all_bases
197
- field :basesWithMaxLimitArray, BaseConnection, null: true, max_page_size: 2, resolver_method: :all_bases_array
198
- field :basesWithDefaultMaxLimitRelation, BaseConnection, null: true, resolver_method: :all_bases
199
- field :basesWithDefaultMaxLimitArray, BaseConnection, null: true, resolver_method: :all_bases_array
200
- field :basesWithLargeMaxLimitRelation, BaseConnection, null: true, max_page_size: 1000, resolver_method: :all_bases
201
- field :basesWithoutNodes, BaseConnectionWithoutNodes, null: true, resolver_method: :all_bases_array
202
-
203
- field :basesAsSequelDataset, BasesConnectionWithTotalCountType, null: true, connection: true, max_page_size: 1000 do
204
- argument :nameIncludes, String, required: false
205
- end
206
-
207
- def bases_as_sequel_dataset(name_includes: nil)
208
- all_bases = SequelBase.where(faction_id: @object.id)
209
- if name_includes
210
- all_bases = all_bases.where(Sequel.like(:name, "%#{name_includes}%"))
211
- end
212
- all_bases
213
- end
214
-
215
- field :basesWithCustomEdge, CustomEdgeBaseConnectionType, null: true, connection: true, resolver_method: :lazy_bases
216
-
217
- def lazy_bases
218
- LazyNodesWrapper.new(object.bases)
219
- end
220
- end
221
-
222
- class IntroduceShipMutation < GraphQL::Schema::RelayClassicMutation
223
- description "Add a ship to this faction"
224
-
225
- # Nested under `input` in the query:
226
- argument :ship_name, String, required: false
227
- argument :faction_id, ID, required: true
228
-
229
- # Result may have access to these fields:
230
- field :ship_edge, Ship.edge_type, null: true
231
- field :faction, Faction, null: true
232
- field :aliased_faction, Faction, hash_key: :aliased_faction, null: true
233
-
234
- def resolve(ship_name: nil, faction_id:)
235
- if ship_name == 'Millennium Falcon'
236
- GraphQL::ExecutionError.new("Sorry, Millennium Falcon ship is reserved")
237
- elsif ship_name == 'Leviathan'
238
- raise GraphQL::ExecutionError.new("🔥")
239
- elsif ship_name == "Ebon Hawk"
240
- LazyWrapper.new { raise GraphQL::ExecutionError.new("💥")}
241
- else
242
- ship = DATA.create_ship(ship_name, faction_id)
243
- faction = DATA["Faction"][faction_id]
244
- connection_class = GraphQL::Relay::BaseConnection.connection_for_nodes(faction.ships)
245
- ships_connection = connection_class.new(faction.ships, {ship_name: ship_name, faction: faction})
246
- ship_edge = GraphQL::Relay::Edge.new(ship, ships_connection)
247
- result = {
248
- ship_edge: ship_edge, # support new-style, too
249
- faction: faction,
250
- aliased_faction: faction,
251
- }
252
- if ship_name == "Slave II"
253
- LazyWrapper.new(result)
254
- else
255
- result
256
- end
257
- end
258
- end
259
- end
260
-
261
- # GraphQL-Batch knockoff
262
- class LazyLoader
263
- def self.defer(ctx, model, id)
264
- ids = ctx.namespace(:loading)[model] ||= []
265
- ids << id
266
- self.new(model: model, id: id, context: ctx)
267
- end
268
-
269
- def initialize(model:, id:, context:)
270
- @model = model
271
- @id = id
272
- @context = context
273
- end
274
-
275
- def value
276
- loaded = @context.namespace(:loaded)[@model] ||= {}
277
- if loaded.empty?
278
- ids = @context.namespace(:loading)[@model]
279
- # Example custom tracing
280
- @context.trace("lazy_loader", { ids: ids, model: @model}) do
281
- records = @model.where(id: ids)
282
- records.each do |record|
283
- loaded[record.id.to_s] = record
284
- end
285
- end
286
- end
287
-
288
- loaded[@id]
289
- end
290
- end
291
-
292
- class LazyWrapper
293
- def initialize(value = nil, &block)
294
- if block_given?
295
- @lazy_value = block
296
- else
297
- @value = value
298
- end
299
- end
300
-
301
- def value
302
- @resolved_value = @value || @lazy_value.call
303
- end
304
- end
305
-
306
- LazyNodesWrapper = Struct.new(:relation)
307
- class LazyNodesRelationConnection < GraphQL::Relay::RelationConnection
308
- def initialize(wrapper, *args)
309
- super(wrapper.relation, *args)
310
- end
311
-
312
- def edge_nodes
313
- LazyWrapper.new { super }
314
- end
315
- end
316
-
317
- GraphQL::Relay::BaseConnection.register_connection_implementation(LazyNodesWrapper, LazyNodesRelationConnection)
318
-
319
- class QueryType < GraphQL::Schema::Object
320
- graphql_name "Query"
321
-
322
- field :rebels, Faction, null: true
323
- def rebels
324
- StarWars::DATA["Faction"]["1"]
325
- end
326
-
327
- field :empire, Faction, null: true
328
- def empire
329
- StarWars::DATA["Faction"]["2"]
330
- end
331
-
332
- field :largestBase, BaseType, null: true
333
-
334
- def largest_base
335
- Base.find(3)
336
- end
337
-
338
- field :newestBasesGroupedByFaction, BaseConnection, null: true
339
-
340
- def newest_bases_grouped_by_faction
341
- Base
342
- .having('id in (select max(id) from bases group by faction_id)')
343
- .group(:id)
344
- .order('faction_id desc')
345
- end
346
-
347
- field :basesWithNullName, BaseConnection, null: false
348
-
349
- def bases_with_null_name
350
- [OpenStruct.new(id: nil)]
351
- end
352
-
353
- if TESTING_INTERPRETER
354
- add_field(GraphQL::Types::Relay::NodeField)
355
- else
356
- field :node, field: GraphQL::Relay::Node.field
357
- end
358
-
359
- if TESTING_INTERPRETER
360
- field :node_with_custom_resolver, GraphQL::Types::Relay::Node, null: true do
361
- argument :id, ID, required: true
362
- end
363
- def node_with_custom_resolver(id:)
364
- StarWars::DATA["Faction"]["1"]
365
- end
366
- else
367
- custom_node_field = GraphQL::Relay::Node.field do
368
- resolve ->(_, _, _) { StarWars::DATA["Faction"]["1"] }
369
- end
370
- field :nodeWithCustomResolver, field: custom_node_field
371
- end
372
-
373
- if TESTING_INTERPRETER
374
- add_field(GraphQL::Types::Relay::NodesField)
375
- else
376
- field :nodes, field: GraphQL::Relay::Node.plural_field
377
- end
378
-
379
- if TESTING_INTERPRETER
380
- field :nodes_with_custom_resolver, [GraphQL::Types::Relay::Node, null: true], null: true do
381
- argument :ids, [ID], required: true
382
- end
383
- def nodes_with_custom_resolver(ids:)
384
- [StarWars::DATA["Faction"]["1"], StarWars::DATA["Faction"]["2"]]
385
- end
386
- else
387
- field :nodesWithCustomResolver, field: GraphQL::Relay::Node.plural_field(
388
- resolve: ->(_, _, _) { [StarWars::DATA["Faction"]["1"], StarWars::DATA["Faction"]["2"]] }
389
- )
390
- end
391
-
392
- field :batchedBase, BaseType, null: true do
393
- argument :id, ID, required: true
394
- end
395
-
396
- def batched_base(id:)
397
- LazyLoader.defer(@context, Base, id)
398
- end
399
- end
400
-
401
- class MutationType < GraphQL::Schema::Object
402
- graphql_name "Mutation"
403
- field :introduceShip, mutation: IntroduceShipMutation
404
- end
405
-
406
- class ClassNameRecorder
407
- def initialize(context_key)
408
- @context_key = context_key
409
- end
410
-
411
- def instrument(type, field)
412
- inner_resolve = field.resolve_proc
413
- key = @context_key
414
- field.redefine {
415
- resolve ->(o, a, c) {
416
- res = inner_resolve.call(o, a, c)
417
- if c[key]
418
- c[key] << res.class.name
419
- end
420
- res
421
- }
422
- }
423
- end
424
- end
425
-
426
- class Schema < GraphQL::Schema
427
- query(QueryType)
428
- mutation(MutationType)
429
- default_max_page_size 3
430
-
431
- if TESTING_INTERPRETER
432
- use GraphQL::Execution::Interpreter
433
- end
434
-
435
- def self.resolve_type(type, object, ctx)
436
- if object == :test_error
437
- :not_a_type
438
- elsif object.is_a?(Base)
439
- BaseType
440
- elsif DATA["Faction"].values.include?(object)
441
- Faction
442
- elsif DATA["Ship"].values.include?(object)
443
- Ship
444
- else
445
- nil
446
- end
447
- end
448
-
449
- def self.object_from_id(node_id, ctx)
450
- type_name, id = GraphQL::Schema::UniqueWithinType.decode(node_id)
451
- StarWars::DATA[type_name][id]
452
- end
453
-
454
- def self.id_from_object(object, type, ctx)
455
- GraphQL::Schema::UniqueWithinType.encode(type.graphql_name, object.id)
456
- end
457
-
458
- lazy_resolve(LazyWrapper, :value)
459
- lazy_resolve(LazyLoader, :value)
460
-
461
- instrument(:field, ClassNameRecorder.new(:before_built_ins))
462
- instrument(:field, ClassNameRecorder.new(:after_built_ins), after_built_ins: true)
463
- end
464
- end