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,43 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- module InstrumentationSpec
5
- module SomeInterface
6
- include GraphQL::Schema::Interface
7
- field :never_called, String, null: false
8
-
9
- def never_called
10
- "should never be called"
11
- end
12
- end
13
-
14
- class SomeType < GraphQL::Schema::Object
15
- implements SomeInterface
16
- end
17
-
18
- class Query < GraphQL::Schema::Object
19
- field :some_field, [SomeInterface], null: true
20
-
21
- def some_field
22
- nil
23
- end
24
- end
25
-
26
- class Schema < GraphQL::Schema
27
- query Query
28
- orphan_types [SomeType]
29
- if TESTING_INTERPRETER
30
- use GraphQL::Execution::Interpreter
31
- end
32
- end
33
- end
34
-
35
- describe GraphQL::Schema::Member::Instrumentation do
36
- describe "resolving nullable interface lists to nil" do
37
- let(:query) { "query { someField { neverCalled } }"}
38
- it "returns nil instead of failing" do
39
- result = InstrumentationSpec::Schema.execute(query)
40
- assert_nil(result["someField"])
41
- end
42
- end
43
- end
@@ -1,215 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe GraphQL::Schema::Interface do
5
- let(:interface) { Jazz::GloballyIdentifiableType }
6
-
7
- describe ".path" do
8
- it "is the name" do
9
- assert_equal "GloballyIdentifiable", interface.path
10
- end
11
- end
12
-
13
- describe "type info" do
14
- it "tells its type info" do
15
- assert_equal "GloballyIdentifiable", interface.graphql_name
16
- assert_equal 2, interface.fields.size
17
- end
18
-
19
- module NewInterface1
20
- include Jazz::GloballyIdentifiableType
21
- end
22
-
23
- module NewInterface2
24
- include Jazz::GloballyIdentifiableType
25
- def new_method
26
- end
27
- end
28
-
29
- it "can override methods" do
30
- new_object_1 = Class.new(GraphQL::Schema::Object) do
31
- implements NewInterface1
32
- end
33
-
34
- assert_equal 2, new_object_1.fields.size
35
- assert new_object_1.method_defined?(:id)
36
-
37
- new_object_2 = Class.new(GraphQL::Schema::Object) do
38
- graphql_name "XYZ"
39
- implements NewInterface2
40
- field :id, "ID", null: false, description: "The ID !!!!!"
41
- end
42
-
43
- assert_equal 2, new_object_2.fields.size
44
- # It got the new method
45
- assert new_object_2.method_defined?(:new_method)
46
- # And the inherited method
47
- assert new_object_2.method_defined?(:id)
48
-
49
- # It gets an overridden description:
50
- assert_equal "The ID !!!!!", new_object_2.graphql_definition.fields["id"].description
51
- end
52
- end
53
-
54
- describe ".to_graphql" do
55
- it "creates an InterfaceType" do
56
- interface_type = interface.to_graphql
57
- assert_equal "GloballyIdentifiable", interface_type.name
58
- field = interface_type.all_fields.first
59
- assert_equal "id", field.name
60
- assert_equal GraphQL::ID_TYPE.to_non_null_type, field.type
61
- assert_equal "A unique identifier for this object", field.description
62
- assert_nil interface_type.resolve_type_proc
63
- assert_empty interface_type.orphan_types
64
- end
65
-
66
- it "can specify a resolve_type method" do
67
- interface = Module.new do
68
- include GraphQL::Schema::Interface
69
- graphql_name "MyInterface"
70
-
71
- module self::DefinitionMethods # rubocop:disable Style/ClassAndModuleChildren
72
- def resolve_type(_object, _context)
73
- "MyType"
74
- end
75
- end
76
- end
77
-
78
- interface_type = interface.to_graphql
79
- assert_equal "MyType", interface_type.resolve_type_proc.call(nil, nil)
80
- end
81
-
82
- it "can specify orphan types" do
83
- interface = Module.new do
84
- include GraphQL::Schema::Interface
85
- graphql_name "MyInterface"
86
- orphan_types Dummy::Cheese, Dummy::Honey
87
- end
88
-
89
- interface_type = interface.to_graphql
90
- assert_equal [Dummy::Cheese, Dummy::Honey], interface_type.orphan_types
91
- end
92
- end
93
-
94
- it 'supports global_id_field' do
95
- object = Module.new do
96
- include GraphQL::Schema::Interface
97
- graphql_name 'GlobalIdFieldTest'
98
- global_id_field :uuid
99
- end.to_graphql
100
-
101
- uuid_field = object.fields["uuid"]
102
-
103
- assert_equal GraphQL::NonNullType, uuid_field.type.class
104
- assert_equal GraphQL::ScalarType, uuid_field.type.unwrap.class
105
- assert_equal(
106
- GraphQL::Schema::Member::GraphQLTypeNames::ID,
107
- uuid_field.type.unwrap.name
108
- )
109
- end
110
-
111
- describe "using `include`" do
112
- it "raises" do
113
- err = assert_raises RuntimeError do
114
- Class.new(GraphQL::Schema::Object) do
115
- include(Jazz::GloballyIdentifiableType)
116
- end
117
- end
118
-
119
- assert_includes err.message, "implements(Jazz::GloballyIdentifiableType)"
120
- end
121
- end
122
-
123
- describe "in queries" do
124
- it "works" do
125
- query_str = <<-GRAPHQL
126
- {
127
- piano: find(id: "Instrument/Piano") {
128
- id
129
- upcasedId
130
- ... on Instrument {
131
- family
132
- }
133
- }
134
- }
135
- GRAPHQL
136
-
137
- res = Jazz::Schema.execute(query_str)
138
- expected_piano = {
139
- "id" => "Instrument/Piano",
140
- "upcasedId" => "INSTRUMENT/PIANO",
141
- "family" => "KEYS",
142
- }
143
- assert_equal(expected_piano, res["data"]["piano"])
144
- end
145
-
146
- it "applies custom field attributes" do
147
- query_str = <<-GRAPHQL
148
- {
149
- find(id: "Ensemble/Bela Fleck and the Flecktones") {
150
- upcasedId
151
- ... on Ensemble {
152
- name
153
- }
154
- }
155
- }
156
- GRAPHQL
157
-
158
- res = Jazz::Schema.execute(query_str)
159
- expected_data = {
160
- "upcasedId" => "ENSEMBLE/BELA FLECK AND THE FLECKTONES",
161
- "name" => "Bela Fleck and the Flecktones"
162
- }
163
- assert_equal(expected_data, res["data"]["find"])
164
- end
165
- end
166
-
167
- describe ':DefinitionMethods' do
168
- module InterfaceA
169
- include GraphQL::Schema::Interface
170
-
171
- definition_methods do
172
- def some_method
173
- 42
174
- end
175
- end
176
- end
177
-
178
- module InterfaceB
179
- include GraphQL::Schema::Interface
180
- end
181
-
182
- module InterfaceC
183
- include GraphQL::Schema::Interface
184
- end
185
-
186
- module InterfaceD
187
- include InterfaceA
188
-
189
- definition_methods do
190
- def some_method
191
- 'not 42'
192
- end
193
- end
194
- end
195
-
196
- module InterfaceE
197
- include InterfaceD
198
- end
199
-
200
- it "doesn't overwrite them when including multiple interfaces" do
201
- def_methods = InterfaceC::DefinitionMethods
202
-
203
- InterfaceC.module_eval do
204
- include InterfaceA
205
- include InterfaceB
206
- end
207
-
208
- assert_equal(InterfaceC::DefinitionMethods, def_methods)
209
- end
210
-
211
- it "follows the normal Ruby ancestor chain when including other interfaces" do
212
- assert_equal('not 42', InterfaceE.some_method)
213
- end
214
- end
215
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe GraphQL::Schema::IntrospectionSystem do
5
- describe "custom introspection" do
6
- it "serves custom fields on types" do
7
- res = Jazz::Schema.execute("{ __schema { isJazzy } }")
8
- assert_equal true, res["data"]["__schema"]["isJazzy"]
9
- end
10
-
11
- it "serves overridden fields on types" do
12
- res = Jazz::Schema.execute(%|{ __type(name: "Ensemble") { name } }|)
13
- assert_equal "ENSEMBLE", res["data"]["__type"]["name"]
14
- end
15
-
16
- it "serves custom entry points" do
17
- res = Jazz::Schema.execute("{ __classname }", root_value: Set.new)
18
- assert_equal "Set", res["data"]["__classname"]
19
- end
20
-
21
- it "calls authorization methods of those types" do
22
- res = Jazz::Schema.execute(%|{ __type(name: "Ensemble") { name } }|)
23
- assert_equal "ENSEMBLE", res["data"]["__type"]["name"]
24
-
25
- unauth_res = Jazz::Schema.execute(%|{ __type(name: "Ensemble") { name } }|, context: { cant_introspect: true })
26
- assert_nil unauth_res["data"].fetch("__type")
27
- assert_equal ["You're not allowed to introspect here"], unauth_res["errors"].map { |e| e["message"] }
28
- end
29
-
30
- it "serves custom dynamic fields" do
31
- res = Jazz::Schema.execute("{ nowPlaying { __typename __typenameLength __astNodeClass } }")
32
- assert_equal "Ensemble", res["data"]["nowPlaying"]["__typename"]
33
- assert_equal 8, res["data"]["nowPlaying"]["__typenameLength"]
34
- assert_equal "GraphQL::Language::Nodes::Field", res["data"]["nowPlaying"]["__astNodeClass"]
35
- end
36
-
37
- it "doesn't affect other schemas" do
38
- res = Dummy::Schema.execute("{ __schema { isJazzy } }")
39
- assert_equal 1, res["errors"].length
40
-
41
- res = Dummy::Schema.execute("{ __classname }", root_value: Set.new)
42
- assert_equal 1, res["errors"].length
43
-
44
- res = Dummy::Schema.execute("{ ensembles { __typenameLength } }")
45
- assert_equal 1, res["errors"].length
46
- end
47
-
48
- it "runs the introspection query" do
49
- res = Jazz::Schema.execute(GraphQL::Introspection::INTROSPECTION_QUERY)
50
- assert res
51
- query_type = res["data"]["__schema"]["types"].find { |t| t["name"] == "QUERY" }
52
- ensembles_field = query_type["fields"].find { |f| f["name"] == "ensembles" }
53
- assert_equal [], ensembles_field["args"]
54
- end
55
- end
56
-
57
- describe "#disable_introspection_entry_points" do
58
- let(:schema) { Jazz::Schema }
59
-
60
- it "allows entry point introspection by default" do
61
- res = schema.execute("{ __schema { types { name } } }")
62
- assert res
63
-
64
- types = res["data"]["__schema"]["types"]
65
- refute_empty types
66
- end
67
-
68
- describe "when entry points introspection is disabled" do
69
- let(:schema) { Jazz::SchemaWithoutIntrospection }
70
-
71
- it "returns error" do
72
- res = schema.execute("{ __schema { types { name } } }")
73
- assert res
74
-
75
- assert_nil res["data"]
76
- assert_equal ["Field '__schema' doesn't exist on type 'Query'"], res["errors"].map { |e| e["message"] }
77
- end
78
- end
79
- end
80
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe GraphQL::Schema::List do
6
- let(:of_type) { Jazz::Musician }
7
- let(:list_type) { GraphQL::Schema::List.new(of_type) }
8
-
9
- it "returns list? to be true" do
10
- assert list_type.list?
11
- end
12
-
13
- it "returns non_null? to be false" do
14
- refute list_type.non_null?
15
- end
16
-
17
- it "returns kind to be GraphQL::TypeKinds::LIST" do
18
- assert_equal GraphQL::TypeKinds::LIST, list_type.kind
19
- end
20
-
21
- it "returns correct type signature" do
22
- assert_equal "[Musician]", list_type.to_type_signature
23
- end
24
-
25
- describe "comparison operator" do
26
- it "will return false if list types 'of_type' are different" do
27
- new_of_type = Jazz::InspectableKey
28
- new_list_type = GraphQL::Schema::List.new(new_of_type)
29
-
30
- refute_equal list_type, new_list_type
31
- end
32
-
33
- it "will return true if list types 'of_type' are the same" do
34
- new_of_type = Jazz::Musician
35
- new_list_type = GraphQL::Schema::List.new(new_of_type)
36
-
37
- assert_equal list_type, new_list_type
38
- end
39
- end
40
-
41
- describe "to_graphql" do
42
- it "will return a list type" do
43
- assert_kind_of GraphQL::ListType, list_type.to_graphql
44
- end
45
- end
46
-
47
- describe "validation" do
48
- class ListEnumValidationSchema < GraphQL::Schema
49
- class Item < GraphQL::Schema::Enum
50
- value "A"
51
- value "B"
52
- end
53
-
54
- class Query < GraphQL::Schema::Object
55
- field :echo, [Item], null: false do
56
- argument :items, [Item], required: true
57
- end
58
-
59
- def echo(items:)
60
- items
61
- end
62
- end
63
-
64
- query(Query)
65
- end
66
-
67
- it "checks non-null lists of enums" do
68
- res = ListEnumValidationSchema.execute "{ echo(items: [A, B, \"C\"]) }"
69
- expected_error = "Argument 'items' on Field 'echo' has an invalid value. Expected type '[Item!]!'."
70
- assert_equal [expected_error], res["errors"].map { |e| e["message"] }
71
- end
72
- end
73
- end
@@ -1,350 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe GraphQL::Schema::Loader do
5
- let(:schema) {
6
- node_type = GraphQL::InterfaceType.define do
7
- name "Node"
8
-
9
- field :id, !types.ID
10
- end
11
-
12
- choice_type = GraphQL::EnumType.define do
13
- name "Choice"
14
-
15
- value "FOO", value: :foo
16
- value "BAR"
17
- end
18
-
19
- sub_input_type = GraphQL::InputObjectType.define do
20
- name "Sub"
21
- input_field :string, types.String
22
- end
23
-
24
- big_int_type = GraphQL::ScalarType.define do
25
- name "BigInt"
26
- coerce_input ->(value, _ctx) { value =~ /\d+/ ? Integer(value) : nil }
27
- coerce_result ->(value, _ctx) { value.to_s }
28
- end
29
-
30
- variant_input_type = GraphQL::InputObjectType.define do
31
- name "Varied"
32
- input_field :id, types.ID
33
- input_field :int, types.Int
34
- input_field :bigint, big_int_type, default_value: 2**54
35
- input_field :float, types.Float
36
- input_field :bool, types.Boolean
37
- input_field :enum, choice_type
38
- input_field :sub, types[sub_input_type]
39
- end
40
-
41
- variant_input_type_with_nulls = GraphQL::InputObjectType.define do
42
- name "VariedWithNulls"
43
- input_field :id, types.ID, default_value: nil
44
- input_field :int, types.Int, default_value: nil
45
- input_field :bigint, big_int_type, default_value: nil
46
- input_field :float, types.Float, default_value: nil
47
- input_field :bool, types.Boolean, default_value: nil
48
- input_field :enum, choice_type, default_value: nil
49
- input_field :sub, types[sub_input_type], default_value: nil
50
- end
51
-
52
- comment_type = GraphQL::ObjectType.define do
53
- name "Comment"
54
- description "A blog comment"
55
- interfaces [node_type]
56
-
57
- field :body, !types.String
58
-
59
- field :fieldWithArg, types.Int do
60
- argument :bigint, big_int_type, default_value: 2**54
61
- end
62
- end
63
-
64
- media_type = GraphQL::InterfaceType.define do
65
- name "Media"
66
- description "!!!"
67
- field :type, !types.String
68
- end
69
-
70
- video_type = GraphQL::ObjectType.define do
71
- name "Video"
72
- interfaces [media_type]
73
- end
74
-
75
- audio_type = GraphQL::ObjectType.define do
76
- name "Audio"
77
- interfaces [media_type]
78
- end
79
-
80
- post_type = GraphQL::ObjectType.define do
81
- name "Post"
82
- description "A blog post"
83
-
84
- field :id, !types.ID
85
- field :title, !types.String
86
- field :body, !types.String
87
- field :comments, types[!comment_type]
88
- field :attachment, media_type
89
- end
90
-
91
- content_type = GraphQL::UnionType.define do
92
- name "Content"
93
- description "A post or comment"
94
- possible_types [post_type, comment_type]
95
- end
96
-
97
- query_root = GraphQL::ObjectType.define do
98
- name "Query"
99
- description "The query root of this schema"
100
-
101
- field :post do
102
- type post_type
103
- argument :id, !types.ID
104
- argument :varied, variant_input_type, default_value: { id: "123", int: 234, float: 2.3, enum: :foo, sub: [{ string: "str" }] }
105
- argument :variedWithNull, variant_input_type_with_nulls, default_value: { id: nil, int: nil, float: nil, enum: nil, sub: nil, bigint: nil, bool: nil }
106
- argument :variedArray, types[variant_input_type], default_value: [{ id: "123", int: 234, float: 2.3, enum: :foo, sub: [{ string: "str" }] }]
107
- argument :enum, choice_type, default_value: :foo
108
- argument :array, types[!types.String], default_value: ["foo", "bar"]
109
- end
110
-
111
- field :content do
112
- type content_type
113
- end
114
- end
115
-
116
- ping_mutation = GraphQL::Relay::Mutation.define do
117
- name "Ping"
118
- end
119
-
120
- mutation_root = GraphQL::ObjectType.define do
121
- name "Mutation"
122
- field :ping, field: ping_mutation.field
123
- end
124
-
125
- GraphQL::Schema.define(
126
- query: query_root,
127
- mutation: mutation_root,
128
- orphan_types: [audio_type, video_type],
129
- resolve_type: ->(a,b,c) { :pass },
130
- )
131
- }
132
-
133
- let(:schema_json) {
134
- schema.execute(GraphQL::Introspection::INTROSPECTION_QUERY)
135
- }
136
-
137
- describe "load" do
138
- def assert_deep_equal(expected_type, actual_type)
139
- assert_equal expected_type.class, actual_type.class
140
-
141
- case actual_type
142
- when Array
143
- actual_type.each_with_index do |obj, index|
144
- assert_deep_equal expected_type[index], obj
145
- end
146
-
147
- when GraphQL::Schema
148
- assert_equal expected_type.query.name, actual_type.query.name
149
- assert_equal expected_type.directives.keys.sort, actual_type.directives.keys.sort
150
- assert_equal expected_type.types.keys.sort, actual_type.types.keys.sort
151
- assert_deep_equal expected_type.types.values.sort_by(&:name), actual_type.types.values.sort_by(&:name)
152
-
153
- when GraphQL::ObjectType, GraphQL::InterfaceType
154
- assert_equal expected_type.name, actual_type.name
155
- assert_equal expected_type.description, actual_type.description
156
- assert_deep_equal expected_type.all_fields.sort_by(&:name), actual_type.all_fields.sort_by(&:name)
157
-
158
- when GraphQL::Field
159
- assert_equal expected_type.name, actual_type.name
160
- assert_equal expected_type.description, actual_type.description
161
- assert_equal expected_type.arguments.keys, actual_type.arguments.keys
162
- assert_deep_equal expected_type.arguments.values, actual_type.arguments.values
163
-
164
- when GraphQL::ScalarType
165
- assert_equal expected_type.name, actual_type.name
166
-
167
- when GraphQL::EnumType
168
- assert_equal expected_type.name, actual_type.name
169
- assert_equal expected_type.description, actual_type.description
170
- assert_equal expected_type.values.keys, actual_type.values.keys
171
- assert_deep_equal expected_type.values.values, actual_type.values.values
172
-
173
- when GraphQL::EnumType::EnumValue
174
- assert_equal expected_type.name, actual_type.name
175
- assert_equal expected_type.description, actual_type.description
176
-
177
- when GraphQL::Argument
178
- assert_equal expected_type.name, actual_type.name
179
- assert_equal expected_type.description, actual_type.description
180
- assert_deep_equal expected_type.type, actual_type.type
181
-
182
- when GraphQL::InputObjectType
183
- assert_equal expected_type.arguments.keys, actual_type.arguments.keys
184
- assert_deep_equal expected_type.arguments.values, actual_type.arguments.values
185
-
186
- when GraphQL::NonNullType, GraphQL::ListType
187
- assert_deep_equal expected_type.of_type, actual_type.of_type
188
-
189
- else
190
- assert_equal expected_type, actual_type
191
- end
192
- end
193
-
194
- let(:loaded_schema) { GraphQL::Schema::Loader.load(schema_json) }
195
-
196
- it "returns the schema" do
197
- assert_deep_equal(schema, loaded_schema)
198
- end
199
-
200
- it "can export the loaded schema" do
201
- assert loaded_schema.execute(GraphQL::Introspection::INTROSPECTION_QUERY)
202
- end
203
-
204
- it "has no-op coerce functions" do
205
- custom_scalar = loaded_schema.types["BigInt"]
206
- assert_equal true, custom_scalar.valid_isolated_input?("anything")
207
- assert_equal true, custom_scalar.valid_isolated_input?(12345)
208
- end
209
-
210
- it "sets correct default values on custom scalar arguments" do
211
- type = loaded_schema.types["Comment"]
212
- field = type.fields['fieldWithArg']
213
- arg = field.arguments['bigint']
214
-
215
- assert_equal((2**54).to_s, arg.default_value)
216
- end
217
-
218
- it "sets correct default values on custom scalar input fields" do
219
- type = loaded_schema.types["Varied"]
220
- field = type.input_fields['bigint']
221
-
222
- assert_equal((2**54).to_s, field.default_value)
223
- end
224
-
225
- it "sets correct default values for complex field arguments" do
226
- type = loaded_schema.types['Query']
227
- field = type.fields['post']
228
-
229
- varied = field.arguments['varied']
230
- assert_equal varied.default_value, { 'id' => "123", 'int' => 234, 'float' => 2.3, 'enum' => "FOO", 'sub' => [{ 'string' => "str" }] }
231
- assert !varied.default_value.key?('bool'), 'Omits default value for unspecified arguments'
232
-
233
- variedArray = field.arguments['variedArray']
234
- assert_equal variedArray.default_value, [{ 'id' => "123", 'int' => 234, 'float' => 2.3, 'enum' => "FOO", 'sub' => [{ 'string' => "str" }] }]
235
- assert !variedArray.default_value.first.key?('bool'), 'Omits default value for unspecified arguments'
236
-
237
- array = field.arguments['array']
238
- assert_equal array.default_value, ["foo", "bar"]
239
- end
240
-
241
- it "does not set default value when there are none on input fields" do
242
- type = loaded_schema.types['Varied']
243
-
244
- assert !type.arguments['id'].default_value?
245
- assert !type.arguments['int'].default_value?
246
- assert type.arguments['bigint'].default_value?
247
- assert !type.arguments['float'].default_value?
248
- assert !type.arguments['bool'].default_value?
249
- assert !type.arguments['enum'].default_value?
250
- assert !type.arguments['sub'].default_value?
251
- end
252
-
253
- it "sets correct default values `null` on input fields" do
254
- type = loaded_schema.types['VariedWithNulls']
255
-
256
- assert type.arguments['id'].default_value?
257
- assert type.arguments['id'].default_value.nil?
258
-
259
- assert type.arguments['int'].default_value?
260
- assert type.arguments['int'].default_value.nil?
261
-
262
- assert type.arguments['bigint'].default_value?
263
- assert type.arguments['bigint'].default_value.nil?
264
-
265
- assert type.arguments['float'].default_value?
266
- assert type.arguments['float'].default_value.nil?
267
-
268
- assert type.arguments['bool'].default_value?
269
- assert type.arguments['bool'].default_value.nil?
270
-
271
- assert type.arguments['enum'].default_value?
272
- assert type.arguments['enum'].default_value.nil?
273
-
274
- assert type.arguments['sub'].default_value?
275
- assert type.arguments['sub'].default_value.nil?
276
- end
277
-
278
- it "doesnt warn about method conflicts (because it doesn't make method accesses)" do
279
- assert_output "", "" do
280
- GraphQL::Schema.from_introspection({
281
- "data" => {
282
- "__schema" => {
283
- "queryType" => {
284
- "name" => "Query"
285
- },
286
- "mutationType" => nil,
287
- "subscriptionType" => nil,
288
- "types" => [
289
- {
290
- "kind" => "OBJECT",
291
- "name" => "Query",
292
- "description" => nil,
293
- "fields" => [
294
- {
295
- "name" => "int",
296
- "description" => nil,
297
- "args" => [
298
- {
299
- "name" => "method",
300
- "description" => nil,
301
- "type" => {
302
- "kind" => "SCALAR",
303
- "name" => "Int",
304
- "ofType" => nil
305
- },
306
- "defaultValue" => nil
307
- }
308
- ],
309
- "type" => {
310
- "kind" => "SCALAR",
311
- "name" => "Int",
312
- "ofType" => nil
313
- },
314
- "isDeprecated" => false,
315
- "deprecationReason" => nil
316
- }
317
- ],
318
- "inputFields" => nil,
319
- "interfaces" => [
320
-
321
- ],
322
- "enumValues" => nil,
323
- "possibleTypes" => nil
324
- },
325
- {
326
- "kind" => "SCALAR",
327
- "name" => "Int",
328
- "description" => "Represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.",
329
- "fields" => nil,
330
- "inputFields" => nil,
331
- "interfaces" => nil,
332
- "enumValues" => nil,
333
- "possibleTypes" => nil
334
- },
335
- ]
336
- }
337
- }
338
- })
339
- end
340
- end
341
-
342
- it "sets correct default values `nil` on complex field arguments" do
343
- type = loaded_schema.types['Query']
344
- field = type.fields['post']
345
- arg = field.arguments['variedWithNull']
346
-
347
- assert_equal arg.default_value, { 'id' => nil, 'int' => nil, 'float' => nil, 'enum' => nil, 'sub' => nil, 'bool' => nil, 'bigint' => nil }
348
- end
349
- end
350
- end