graphql 1.2.6 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (278) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql.rb +3 -1
  3. data/lib/graphql/analysis.rb +1 -0
  4. data/lib/graphql/analysis/analyze_query.rb +1 -0
  5. data/lib/graphql/analysis/field_usage.rb +1 -0
  6. data/lib/graphql/analysis/max_query_complexity.rb +1 -0
  7. data/lib/graphql/analysis/max_query_depth.rb +1 -0
  8. data/lib/graphql/analysis/query_complexity.rb +1 -0
  9. data/lib/graphql/analysis/query_depth.rb +1 -0
  10. data/lib/graphql/analysis/reducer_state.rb +1 -0
  11. data/lib/graphql/analysis_error.rb +1 -0
  12. data/lib/graphql/argument.rb +1 -0
  13. data/lib/graphql/base_type.rb +16 -7
  14. data/lib/graphql/boolean_type.rb +1 -0
  15. data/lib/graphql/compatibility.rb +2 -0
  16. data/lib/graphql/compatibility/execution_specification.rb +113 -192
  17. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +53 -0
  18. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +195 -0
  19. data/lib/graphql/compatibility/lazy_execution_specification.rb +186 -0
  20. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +97 -0
  21. data/lib/graphql/compatibility/query_parser_specification.rb +1 -0
  22. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +1 -0
  23. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +1 -0
  24. data/lib/graphql/compatibility/schema_parser_specification.rb +1 -0
  25. data/lib/graphql/define.rb +1 -0
  26. data/lib/graphql/define/assign_argument.rb +1 -0
  27. data/lib/graphql/define/assign_connection.rb +1 -0
  28. data/lib/graphql/define/assign_enum_value.rb +1 -0
  29. data/lib/graphql/define/assign_global_id_field.rb +1 -0
  30. data/lib/graphql/define/assign_object_field.rb +1 -0
  31. data/lib/graphql/define/defined_object_proxy.rb +1 -0
  32. data/lib/graphql/define/instance_definable.rb +11 -12
  33. data/lib/graphql/define/non_null_with_bang.rb +1 -0
  34. data/lib/graphql/define/type_definer.rb +1 -0
  35. data/lib/graphql/directive.rb +1 -0
  36. data/lib/graphql/directive/deprecated_directive.rb +1 -0
  37. data/lib/graphql/directive/include_directive.rb +1 -0
  38. data/lib/graphql/directive/skip_directive.rb +1 -0
  39. data/lib/graphql/enum_type.rb +8 -1
  40. data/lib/graphql/execution.rb +5 -0
  41. data/lib/graphql/execution/directive_checks.rb +1 -0
  42. data/lib/graphql/execution/execute.rb +222 -0
  43. data/lib/graphql/execution/field_result.rb +52 -0
  44. data/lib/graphql/execution/lazy.rb +59 -0
  45. data/lib/graphql/execution/lazy/lazy_method_map.rb +38 -0
  46. data/lib/graphql/execution/lazy/resolve.rb +68 -0
  47. data/lib/graphql/execution/selection_result.rb +84 -0
  48. data/lib/graphql/execution/typecast.rb +4 -4
  49. data/lib/graphql/execution_error.rb +1 -0
  50. data/lib/graphql/field.rb +68 -18
  51. data/lib/graphql/field/resolve.rb +1 -0
  52. data/lib/graphql/float_type.rb +1 -0
  53. data/lib/graphql/id_type.rb +1 -0
  54. data/lib/graphql/input_object_type.rb +6 -0
  55. data/lib/graphql/int_type.rb +1 -0
  56. data/lib/graphql/interface_type.rb +6 -0
  57. data/lib/graphql/internal_representation.rb +2 -1
  58. data/lib/graphql/internal_representation/node.rb +2 -1
  59. data/lib/graphql/internal_representation/rewrite.rb +1 -0
  60. data/lib/graphql/internal_representation/selection.rb +85 -0
  61. data/lib/graphql/introspection.rb +1 -0
  62. data/lib/graphql/introspection/arguments_field.rb +1 -0
  63. data/lib/graphql/introspection/directive_location_enum.rb +1 -0
  64. data/lib/graphql/introspection/directive_type.rb +1 -0
  65. data/lib/graphql/introspection/enum_value_type.rb +1 -0
  66. data/lib/graphql/introspection/enum_values_field.rb +1 -0
  67. data/lib/graphql/introspection/field_type.rb +1 -0
  68. data/lib/graphql/introspection/fields_field.rb +1 -0
  69. data/lib/graphql/introspection/input_fields_field.rb +1 -0
  70. data/lib/graphql/introspection/input_value_type.rb +2 -1
  71. data/lib/graphql/introspection/interfaces_field.rb +1 -0
  72. data/lib/graphql/introspection/introspection_query.rb +1 -0
  73. data/lib/graphql/introspection/of_type_field.rb +1 -0
  74. data/lib/graphql/introspection/possible_types_field.rb +1 -0
  75. data/lib/graphql/introspection/schema_field.rb +1 -0
  76. data/lib/graphql/introspection/schema_type.rb +1 -0
  77. data/lib/graphql/introspection/type_by_name_field.rb +1 -0
  78. data/lib/graphql/introspection/type_kind_enum.rb +1 -0
  79. data/lib/graphql/introspection/type_type.rb +1 -0
  80. data/lib/graphql/introspection/typename_field.rb +1 -0
  81. data/lib/graphql/invalid_null_error.rb +17 -7
  82. data/lib/graphql/language.rb +10 -0
  83. data/lib/graphql/language/comments.rb +2 -1
  84. data/lib/graphql/language/definition_slice.rb +1 -0
  85. data/lib/graphql/language/generation.rb +25 -24
  86. data/lib/graphql/language/nodes.rb +1 -0
  87. data/lib/graphql/language/token.rb +1 -0
  88. data/lib/graphql/language/visitor.rb +1 -0
  89. data/lib/graphql/list_type.rb +1 -0
  90. data/lib/graphql/non_null_type.rb +2 -1
  91. data/lib/graphql/object_type.rb +12 -0
  92. data/lib/graphql/query.rb +40 -43
  93. data/lib/graphql/query/arguments.rb +1 -0
  94. data/lib/graphql/query/context.rb +31 -7
  95. data/lib/graphql/query/executor.rb +8 -1
  96. data/lib/graphql/query/input_validation_result.rb +1 -0
  97. data/lib/graphql/query/literal_input.rb +1 -0
  98. data/lib/graphql/query/serial_execution.rb +3 -4
  99. data/lib/graphql/query/serial_execution/field_resolution.rb +15 -10
  100. data/lib/graphql/query/serial_execution/operation_resolution.rb +3 -5
  101. data/lib/graphql/query/serial_execution/selection_resolution.rb +4 -5
  102. data/lib/graphql/query/serial_execution/value_resolution.rb +26 -11
  103. data/lib/graphql/query/variable_validation_error.rb +1 -0
  104. data/lib/graphql/query/variables.rb +1 -0
  105. data/lib/graphql/relay.rb +1 -0
  106. data/lib/graphql/relay/array_connection.rb +3 -2
  107. data/lib/graphql/relay/base_connection.rb +20 -8
  108. data/lib/graphql/relay/connection_field.rb +1 -0
  109. data/lib/graphql/relay/connection_resolve.rb +14 -1
  110. data/lib/graphql/relay/connection_type.rb +1 -0
  111. data/lib/graphql/relay/edge.rb +1 -0
  112. data/lib/graphql/relay/edge_type.rb +1 -0
  113. data/lib/graphql/relay/global_id_resolve.rb +1 -0
  114. data/lib/graphql/relay/mutation.rb +13 -0
  115. data/lib/graphql/relay/node.rb +1 -0
  116. data/lib/graphql/relay/page_info.rb +1 -0
  117. data/lib/graphql/relay/relation_connection.rb +3 -2
  118. data/lib/graphql/runtime_type_error.rb +4 -0
  119. data/lib/graphql/scalar_type.rb +2 -1
  120. data/lib/graphql/schema.rb +116 -26
  121. data/lib/graphql/schema/base_64_encoder.rb +14 -0
  122. data/lib/graphql/schema/build_from_definition.rb +4 -0
  123. data/lib/graphql/schema/catchall_middleware.rb +1 -0
  124. data/lib/graphql/schema/default_type_error.rb +15 -0
  125. data/lib/graphql/schema/instrumented_field_map.rb +1 -0
  126. data/lib/graphql/schema/invalid_type_error.rb +1 -0
  127. data/lib/graphql/schema/loader.rb +5 -1
  128. data/lib/graphql/schema/middleware_chain.rb +1 -0
  129. data/lib/graphql/schema/possible_types.rb +1 -0
  130. data/lib/graphql/schema/printer.rb +3 -2
  131. data/lib/graphql/schema/reduce_types.rb +1 -0
  132. data/lib/graphql/schema/rescue_middleware.rb +3 -2
  133. data/lib/graphql/schema/timeout_middleware.rb +1 -0
  134. data/lib/graphql/schema/type_expression.rb +1 -0
  135. data/lib/graphql/schema/type_map.rb +1 -0
  136. data/lib/graphql/schema/unique_within_type.rb +1 -0
  137. data/lib/graphql/schema/validation.rb +57 -1
  138. data/lib/graphql/schema/warden.rb +1 -0
  139. data/lib/graphql/static_validation.rb +1 -0
  140. data/lib/graphql/static_validation/all_rules.rb +1 -0
  141. data/lib/graphql/static_validation/arguments_validator.rb +1 -0
  142. data/lib/graphql/static_validation/literal_validator.rb +1 -0
  143. data/lib/graphql/static_validation/message.rb +1 -0
  144. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -0
  145. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -0
  146. data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -0
  147. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -0
  148. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -0
  149. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -0
  150. data/lib/graphql/static_validation/rules/fields_will_merge.rb +6 -3
  151. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +1 -0
  152. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -0
  153. data/lib/graphql/static_validation/rules/fragments_are_finite.rb +1 -0
  154. data/lib/graphql/static_validation/rules/fragments_are_named.rb +1 -0
  155. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -0
  156. data/lib/graphql/static_validation/rules/fragments_are_used.rb +1 -0
  157. data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -0
  158. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +1 -0
  159. data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -0
  160. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +1 -0
  161. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -0
  162. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -0
  163. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -0
  164. data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +1 -0
  165. data/lib/graphql/static_validation/type_stack.rb +1 -0
  166. data/lib/graphql/static_validation/validation_context.rb +2 -1
  167. data/lib/graphql/static_validation/validator.rb +2 -1
  168. data/lib/graphql/string_type.rb +1 -0
  169. data/lib/graphql/type_kinds.rb +1 -0
  170. data/lib/graphql/union_type.rb +13 -0
  171. data/lib/graphql/unresolved_type_error.rb +26 -5
  172. data/lib/graphql/version.rb +2 -1
  173. data/readme.md +1 -5
  174. data/spec/graphql/analysis/analyze_query_spec.rb +1 -0
  175. data/spec/graphql/analysis/field_usage_spec.rb +1 -0
  176. data/spec/graphql/analysis/max_query_complexity_spec.rb +1 -0
  177. data/spec/graphql/analysis/max_query_depth_spec.rb +1 -0
  178. data/spec/graphql/analysis/query_complexity_spec.rb +1 -0
  179. data/spec/graphql/analysis/query_depth_spec.rb +1 -0
  180. data/spec/graphql/argument_spec.rb +1 -0
  181. data/spec/graphql/base_type_spec.rb +13 -0
  182. data/spec/graphql/boolean_type_spec.rb +1 -0
  183. data/spec/graphql/compatibility/execution_specification_spec.rb +1 -0
  184. data/spec/graphql/compatibility/lazy_execution_specification_spec.rb +4 -0
  185. data/spec/graphql/compatibility/query_parser_specification_spec.rb +1 -0
  186. data/spec/graphql/compatibility/schema_parser_specification_spec.rb +1 -0
  187. data/spec/graphql/define/assign_argument_spec.rb +1 -0
  188. data/spec/graphql/define/instance_definable_spec.rb +1 -0
  189. data/spec/graphql/directive_spec.rb +1 -0
  190. data/spec/graphql/enum_type_spec.rb +10 -0
  191. data/spec/graphql/execution/execute_spec.rb +5 -0
  192. data/spec/graphql/execution/lazy_spec.rb +252 -0
  193. data/spec/graphql/execution/typecast_spec.rb +1 -0
  194. data/spec/graphql/execution_error_spec.rb +1 -0
  195. data/spec/graphql/field_spec.rb +17 -0
  196. data/spec/graphql/float_type_spec.rb +1 -0
  197. data/spec/graphql/id_type_spec.rb +1 -0
  198. data/spec/graphql/input_object_type_spec.rb +10 -0
  199. data/spec/graphql/int_type_spec.rb +1 -0
  200. data/spec/graphql/interface_type_spec.rb +10 -0
  201. data/spec/graphql/internal_representation/rewrite_spec.rb +1 -0
  202. data/spec/graphql/introspection/directive_type_spec.rb +1 -0
  203. data/spec/graphql/introspection/input_value_type_spec.rb +1 -0
  204. data/spec/graphql/introspection/introspection_query_spec.rb +1 -0
  205. data/spec/graphql/introspection/schema_type_spec.rb +1 -0
  206. data/spec/graphql/introspection/type_type_spec.rb +1 -0
  207. data/spec/graphql/language/definition_slice_spec.rb +1 -0
  208. data/spec/graphql/language/equality_spec.rb +1 -0
  209. data/spec/graphql/language/generation_spec.rb +1 -0
  210. data/spec/graphql/language/lexer_spec.rb +1 -0
  211. data/spec/graphql/language/nodes_spec.rb +1 -0
  212. data/spec/graphql/language/parser_spec.rb +1 -0
  213. data/spec/graphql/language/visitor_spec.rb +1 -0
  214. data/spec/graphql/list_type_spec.rb +1 -0
  215. data/spec/graphql/non_null_type_spec.rb +17 -0
  216. data/spec/graphql/object_type_spec.rb +19 -0
  217. data/spec/graphql/query/arguments_spec.rb +1 -0
  218. data/spec/graphql/query/context_spec.rb +1 -0
  219. data/spec/graphql/query/executor_spec.rb +1 -0
  220. data/spec/graphql/query/serial_execution/value_resolution_spec.rb +1 -0
  221. data/spec/graphql/query/variables_spec.rb +1 -0
  222. data/spec/graphql/query_spec.rb +25 -0
  223. data/spec/graphql/relay/array_connection_spec.rb +1 -0
  224. data/spec/graphql/relay/base_connection_spec.rb +33 -4
  225. data/spec/graphql/relay/connection_field_spec.rb +1 -0
  226. data/spec/graphql/relay/connection_type_spec.rb +1 -0
  227. data/spec/graphql/relay/mutation_spec.rb +6 -0
  228. data/spec/graphql/relay/node_spec.rb +1 -0
  229. data/spec/graphql/relay/page_info_spec.rb +1 -0
  230. data/spec/graphql/relay/relation_connection_spec.rb +1 -0
  231. data/spec/graphql/scalar_type_spec.rb +1 -0
  232. data/spec/graphql/schema/build_from_definition_spec.rb +9 -1
  233. data/spec/graphql/schema/catchall_middleware_spec.rb +1 -0
  234. data/spec/graphql/schema/loader_spec.rb +7 -0
  235. data/spec/graphql/schema/middleware_chain_spec.rb +1 -0
  236. data/spec/graphql/schema/printer_spec.rb +1 -0
  237. data/spec/graphql/schema/reduce_types_spec.rb +1 -0
  238. data/spec/graphql/schema/rescue_middleware_spec.rb +1 -0
  239. data/spec/graphql/schema/timeout_middleware_spec.rb +1 -0
  240. data/spec/graphql/schema/type_expression_spec.rb +1 -0
  241. data/spec/graphql/schema/unique_within_type_spec.rb +1 -0
  242. data/spec/graphql/schema/validation_spec.rb +55 -0
  243. data/spec/graphql/schema/warden_spec.rb +1 -0
  244. data/spec/graphql/schema_spec.rb +39 -0
  245. data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +1 -0
  246. data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +1 -0
  247. data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +1 -0
  248. data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +1 -0
  249. data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +1 -0
  250. data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +1 -0
  251. data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +515 -31
  252. data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +1 -0
  253. data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +1 -0
  254. data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +1 -0
  255. data/spec/graphql/static_validation/rules/fragments_are_named_spec.rb +1 -0
  256. data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +1 -0
  257. data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +1 -0
  258. data/spec/graphql/static_validation/rules/mutation_root_exists_spec.rb +1 -0
  259. data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +1 -0
  260. data/spec/graphql/static_validation/rules/subscription_root_exists_spec.rb +1 -0
  261. data/spec/graphql/static_validation/rules/unique_directives_per_location_spec.rb +1 -0
  262. data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +1 -0
  263. data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +1 -0
  264. data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +1 -0
  265. data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +1 -0
  266. data/spec/graphql/static_validation/type_stack_spec.rb +1 -0
  267. data/spec/graphql/static_validation/validator_spec.rb +1 -0
  268. data/spec/graphql/string_type_spec.rb +1 -0
  269. data/spec/graphql/union_type_spec.rb +11 -0
  270. data/spec/spec_helper.rb +1 -0
  271. data/spec/support/dairy_app.rb +1 -0
  272. data/spec/support/dairy_data.rb +1 -0
  273. data/spec/support/minimum_input_object.rb +1 -0
  274. data/spec/support/star_wars_data.rb +1 -0
  275. data/spec/support/star_wars_schema.rb +30 -7
  276. data/spec/support/static_validation_helpers.rb +1 -0
  277. metadata +24 -5
  278. data/lib/graphql/internal_representation/selections.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2550713a1eb62110904f3370fc77ce4f9d829efa
4
- data.tar.gz: d70c9b62e551278f6764e5aa4a5a3cdcb973c7be
3
+ metadata.gz: 0019d58e7660531d537f4318a9f77df48ee6c501
4
+ data.tar.gz: b1b229e62437f03ce0f5003a92c2546b733121ad
5
5
  SHA512:
6
- metadata.gz: 86120c08fcf5598c0672ff0a035939ec44a450509d57dcf6ca5627f35c3bb8efcfd1b3be063fa5ea194c40e652390a22a20eb32b2e347026e87ce28100551a96
7
- data.tar.gz: 83692323da75a39f24439aefdf0280d1a64240f332bef934207753dc672edb7fc4da81b8900aeeccbf463409df2497ef25243b98595604bc7676abaa0df775c1
6
+ metadata.gz: 7d9f28b11005ac84e02b4528cd6c75ace38368c7bed476bc08a7c8b5b88e6a2643a2e5a3779da11babcf983aacc30bcc4bf6a69e53da83cc8e0b4ecac042a5f9
7
+ data.tar.gz: 22249283811a82bda630d4d5f24149cfbdea7ad2a7aa9a4583810a318f054093c077b87d6f84550c129e3d431f3a504fa0b97ad109c65b1b89dd0f6e7716e256
data/lib/graphql.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "json"
2
3
  require "set"
3
4
  require "singleton"
@@ -67,6 +68,7 @@ require "graphql/directive"
67
68
  require "graphql/introspection"
68
69
  require "graphql/language"
69
70
  require "graphql/analysis"
71
+ require "graphql/execution"
70
72
  require "graphql/schema"
71
73
  require "graphql/schema/loader"
72
74
  require "graphql/schema/printer"
@@ -74,6 +76,7 @@ require "graphql/schema/printer"
74
76
  # Order does not matter for these:
75
77
 
76
78
  require "graphql/analysis_error"
79
+ require "graphql/runtime_type_error"
77
80
  require "graphql/invalid_null_error"
78
81
  require "graphql/unresolved_type_error"
79
82
  require "graphql/query"
@@ -81,5 +84,4 @@ require "graphql/internal_representation"
81
84
  require "graphql/static_validation"
82
85
  require "graphql/version"
83
86
  require "graphql/relay"
84
- require "graphql/execution"
85
87
  require "graphql/compatibility"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "graphql/analysis/max_query_complexity"
2
3
  require "graphql/analysis/max_query_depth"
3
4
  require "graphql/analysis/query_complexity"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Analysis
3
4
  module_function
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Analysis
3
4
  # A query reducer for tracking both field usage and deprecated field usage.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative "./query_complexity"
2
3
  module GraphQL
3
4
  module Analysis
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative "./query_depth"
2
3
  module GraphQL
3
4
  module Analysis
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Analysis
3
4
  # Calculate the complexity of a query, using {Field#complexity} values.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Analysis
3
4
  # A query reducer for measuring the depth of a given query.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Analysis
3
4
  class ReducerState
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class AnalysisError < GraphQL::ExecutionError
3
4
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  # Used for defined arguments ({Field}, {InputObjectType})
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  # The parent for all type classes.
3
4
  class BaseType
@@ -8,14 +9,20 @@ module GraphQL
8
9
  global_id_field: GraphQL::Define::AssignGlobalIdField,
9
10
  }
10
11
 
11
- attr_accessor :name, :description
12
12
  ensure_defined(:name, :description)
13
13
 
14
- # @!attribute name
15
- # @return [String] the name of this type, must be unique within a Schema
14
+ def initialize_copy(other)
15
+ super
16
+ # Reset these derived defaults
17
+ @connection_type = nil
18
+ @edge_type = nil
19
+ end
20
+
21
+ # @return [String] the name of this type, must be unique within a Schema
22
+ attr_accessor :name
16
23
 
17
- # @!attribute description
18
- # @return [String, nil] a description for this type
24
+ # @return [String, nil] a description for this type
25
+ attr_accessor :description
19
26
 
20
27
  # @param other [GraphQL::BaseType] compare to this object
21
28
  # @return [Boolean] are these types equivalent? (incl. non-null, list)
@@ -102,22 +109,24 @@ module GraphQL
102
109
  end
103
110
  end
104
111
 
105
- # Get the default connection type for this object type
112
+ # @return [GraphQL::ObjectType] The default connection type for this object type
106
113
  def connection_type
107
114
  @connection_type ||= define_connection
108
115
  end
109
116
 
110
117
  # Define a custom connection type for this object type
118
+ # @return [GraphQL::ObjectType]
111
119
  def define_connection(**kwargs, &block)
112
120
  GraphQL::Relay::ConnectionType.create_type(self, **kwargs, &block)
113
121
  end
114
122
 
115
- # Get the default edge type for this object type
123
+ # @return [GraphQL::ObjectType] The default edge type for this object type
116
124
  def edge_type
117
125
  @edge_type ||= define_edge
118
126
  end
119
127
 
120
128
  # Define a custom edge type for this object type
129
+ # @return [GraphQL::ObjectType]
121
130
  def define_edge(**kwargs, &block)
122
131
  GraphQL::Relay::EdgeType.create_type(self, **kwargs, &block)
123
132
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::BOOLEAN_TYPE = GraphQL::ScalarType.define do
2
3
  name "Boolean"
3
4
  description "Represents `true` or `false` values."
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
1
2
  require "graphql/compatibility/execution_specification"
3
+ require "graphql/compatibility/lazy_execution_specification"
2
4
  require "graphql/compatibility/query_parser_specification"
3
5
  require "graphql/compatibility/schema_parser_specification"
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+ require "graphql/compatibility/execution_specification/counter_schema"
3
+ require "graphql/compatibility/execution_specification/specification_schema"
4
+
1
5
  module GraphQL
2
6
  module Compatibility
3
7
  # Test an execution strategy. This spec is not meant as a development aid.
@@ -22,164 +26,22 @@ module GraphQL
22
26
  # - Relay features
23
27
  #
24
28
  module ExecutionSpecification
25
- DATA = {
26
- "1001" => OpenStruct.new({
27
- name: "Fannie Lou Hamer",
28
- birthdate: Time.new(1917, 10, 6),
29
- organization_ids: [],
30
- }),
31
- "1002" => OpenStruct.new({
32
- name: "John Lewis",
33
- birthdate: Time.new(1940, 2, 21),
34
- organization_ids: ["2001"],
35
- }),
36
- "1003" => OpenStruct.new({
37
- name: "Diane Nash",
38
- birthdate: Time.new(1938, 5, 15),
39
- organization_ids: ["2001", "2002"],
40
- }),
41
- "1004" => OpenStruct.new({
42
- name: "Ralph Abernathy",
43
- birthdate: Time.new(1926, 3, 11),
44
- organization_ids: ["2002"],
45
- }),
46
- "2001" => OpenStruct.new({
47
- name: "SNCC",
48
- leader_id: nil, # fail on purpose
49
- }),
50
- "2002" => OpenStruct.new({
51
- name: "SCLC",
52
- leader_id: "1004",
53
- }),
54
- }
55
-
56
29
  # Make a minitest suite for this execution strategy, making sure it
57
30
  # fulfills all the requirements of this library.
58
31
  # @param execution_strategy [<#new, #execute>] An execution strategy class
59
32
  # @return [Class<Minitest::Test>] A test suite for this execution strategy
60
33
  def self.build_suite(execution_strategy)
61
34
  Class.new(Minitest::Test) do
62
- def self.build_schema(execution_strategy)
63
- organization_type = nil
64
-
65
- timestamp_type = GraphQL::ScalarType.define do
66
- name "Timestamp"
67
- coerce_input ->(value) { Time.at(value.to_i) }
68
- coerce_result ->(value) { value.to_i }
69
- end
70
-
71
- named_entity_interface_type = GraphQL::InterfaceType.define do
72
- name "NamedEntity"
73
- field :name, !types.String
74
- end
75
-
76
- person_type = GraphQL::ObjectType.define do
77
- name "Person"
78
- interfaces [named_entity_interface_type]
79
- field :name, !types.String
80
- field :birthdate, timestamp_type
81
- field :age, types.Int do
82
- argument :on, !timestamp_type
83
- resolve ->(obj, args, ctx) {
84
- if obj.birthdate.nil?
85
- nil
86
- else
87
- age_on = args[:on]
88
- age_years = age_on.year - obj.birthdate.year
89
- this_year_birthday = Time.new(age_on.year, obj.birthdate.month, obj.birthdate.day)
90
- if this_year_birthday > age_on
91
- age_years -= 1
92
- end
93
- end
94
- age_years
95
- }
96
- end
97
- field :organizations, types[organization_type] do
98
- resolve ->(obj, args, ctx) {
99
- obj.organization_ids.map { |id| DATA[id] }
100
- }
101
- end
102
- field :first_organization, !organization_type do
103
- resolve ->(obj, args, ctx) {
104
- DATA[obj.organization_ids.first]
105
- }
106
- end
107
- end
108
-
109
- organization_type = GraphQL::ObjectType.define do
110
- name "Organization"
111
- interfaces [named_entity_interface_type]
112
- field :name, !types.String
113
- field :leader, !person_type do
114
- resolve ->(obj, args, ctx) {
115
- DATA[obj.leader_id] || (ctx[:return_error] ? ExecutionError.new("Error on Nullable") : nil)
116
- }
117
- end
118
- field :returnedError, types.String do
119
- resolve ->(o, a, c) {
120
- GraphQL::ExecutionError.new("This error was returned")
121
- }
122
- end
123
- field :raisedError, types.String do
124
- resolve ->(o, a, c) {
125
- raise GraphQL::ExecutionError.new("This error was raised")
126
- }
127
- end
128
-
129
- field :nodePresence, !types[!types.Boolean] do
130
- resolve ->(o, a, ctx) {
131
- [
132
- ctx.irep_node.is_a?(GraphQL::InternalRepresentation::Node),
133
- ctx.ast_node.is_a?(GraphQL::Language::Nodes::AbstractNode),
134
- false, # just testing
135
- ]
136
- }
137
- end
138
- end
139
-
140
- node_union_type = GraphQL::UnionType.define do
141
- name "Node"
142
- possible_types [person_type, organization_type]
143
- end
144
-
145
- query_type = GraphQL::ObjectType.define do
146
- name "Query"
147
- field :node, node_union_type do
148
- argument :id, !types.ID
149
- resolve ->(obj, args, ctx) {
150
- obj[args[:id]]
151
- }
152
- end
153
-
154
- field :organization, !organization_type do
155
- argument :id, !types.ID
156
- resolve ->(obj, args, ctx) {
157
- args[:id].start_with?("2") && obj[args[:id]]
158
- }
159
- end
160
-
161
- field :organizations, types[organization_type] do
162
- resolve ->(obj, args, ctx) {
163
- [obj["2001"], obj["2002"]]
164
- }
165
- end
166
- end
167
-
168
- GraphQL::Schema.define do
169
- query_execution_strategy execution_strategy
170
- query query_type
171
-
172
- resolve_type ->(obj, ctx) {
173
- obj.respond_to?(:birthdate) ? person_type : organization_type
174
- }
175
- end
35
+ class << self
36
+ attr_accessor :counter_schema, :specification_schema
176
37
  end
177
38
 
178
- @@schema = build_schema(execution_strategy)
39
+ self.specification_schema = SpecificationSchema.build(execution_strategy)
40
+ self.counter_schema = CounterSchema.build(execution_strategy)
179
41
 
180
42
  def execute_query(query_string, **kwargs)
181
- kwargs[:root_value] = DATA
182
- @@schema.execute(query_string, **kwargs)
43
+ kwargs[:root_value] = SpecificationSchema::DATA
44
+ self.class.specification_schema.execute(query_string, **kwargs)
183
45
  end
184
46
 
185
47
  def test_it_fetches_data
@@ -220,6 +82,21 @@ module GraphQL
220
82
  assert_equal false, flh.key?("org_n"), "It doesn't apply other type fields"
221
83
  end
222
84
 
85
+ def test_it_iterates_over_each
86
+ query_string = %|
87
+ query getData($nodeId: ID = "1002") {
88
+ node(id: $nodeId) {
89
+ ... on Person {
90
+ organizations { name }
91
+ }
92
+ }
93
+ }
94
+ |
95
+
96
+ res = execute_query(query_string)
97
+ assert_equal ["SNCC"], res["data"]["node"]["organizations"].map { |o| o["name"] }
98
+ end
99
+
223
100
  def test_it_propagates_nulls_to_field
224
101
  query_string = %|
225
102
  query getOrg($id: ID = "2001"){
@@ -329,7 +206,7 @@ module GraphQL
329
206
  }
330
207
  }|
331
208
 
332
- assert_raises(GraphQL::UnresolvedTypeError) {
209
+ err = assert_raises(GraphQL::UnresolvedTypeError) {
333
210
  execute_query(query_string, except: no_org)
334
211
  }
335
212
 
@@ -342,6 +219,11 @@ module GraphQL
342
219
 
343
220
  assert_equal nil, res["data"]
344
221
  assert_equal 1, res["errors"].length
222
+ assert_equal "SNCC", err.value.name
223
+ assert_equal GraphQL::Relay::Node.interface, err.field.type
224
+ assert_equal 1, err.possible_types.length
225
+ assert_equal "Organization", err.resolved_type.name
226
+ assert_equal "Query", err.parent_type.name
345
227
 
346
228
  query_string = %|
347
229
  {
@@ -409,47 +291,7 @@ module GraphQL
409
291
  end
410
292
 
411
293
  def test_it_only_resolves_fields_once_on_typed_fragments
412
- count = 0
413
- counter_type = nil
414
-
415
- has_count_interface = GraphQL::InterfaceType.define do
416
- name "HasCount"
417
- field :count, types.Int
418
- field :counter, ->{ counter_type }
419
- end
420
-
421
- counter_type = GraphQL::ObjectType.define do
422
- name "Counter"
423
- interfaces [has_count_interface]
424
- field :count, types.Int, resolve: ->(o,a,c) { count += 1 }
425
- field :counter, has_count_interface, resolve: ->(o,a,c) { :counter }
426
- end
427
-
428
- alt_counter_type = GraphQL::ObjectType.define do
429
- name "AltCounter"
430
- interfaces [has_count_interface]
431
- field :count, types.Int, resolve: ->(o,a,c) { count += 1 }
432
- field :counter, has_count_interface, resolve: ->(o,a,c) { :counter }
433
- end
434
-
435
- has_counter_interface = GraphQL::InterfaceType.define do
436
- name "HasCounter"
437
- field :counter, counter_type
438
- end
439
-
440
- query_type = GraphQL::ObjectType.define do
441
- name "Query"
442
- interfaces [has_counter_interface]
443
- field :counter, has_count_interface, resolve: ->(o,a,c) { :counter }
444
- end
445
-
446
- schema = GraphQL::Schema.define(
447
- query: query_type,
448
- resolve_type: ->(o, c) { o == :counter ? counter_type : nil },
449
- orphan_types: [alt_counter_type],
450
- )
451
-
452
- res = schema.execute("
294
+ res = self.class.counter_schema.execute("
453
295
  {
454
296
  counter { count }
455
297
  ... on HasCounter {
@@ -462,10 +304,10 @@ module GraphQL
462
304
  "counter" => { "count" => 1 }
463
305
  }
464
306
  assert_equal expected_data, res["data"]
465
- assert_equal 1, count
307
+ assert_equal 1, self.class.counter_schema.metadata[:count]
466
308
 
467
309
  # Deep typed children are correctly distinguished:
468
- res = schema.execute("
310
+ res = self.class.counter_schema.execute("
469
311
  {
470
312
  counter {
471
313
  ... on Counter {
@@ -483,6 +325,85 @@ module GraphQL
483
325
  }
484
326
  assert_equal expected_data, res["data"]
485
327
  end
328
+
329
+ def test_it_runs_middleware
330
+ log = []
331
+ query_string = %|
332
+ {
333
+ node(id: "2001") {
334
+ __typename
335
+ }
336
+ }|
337
+ res = execute_query(query_string, context: {middleware_log: log})
338
+ assert_equal ["node", "__typename"], log
339
+ end
340
+
341
+ def test_it_uses_type_error_hooks_for_invalid_nulls
342
+ log = []
343
+ query_string = %|
344
+ {
345
+ node(id: "1001") {
346
+ ... on Person {
347
+ name
348
+ first_organization {
349
+ leader {
350
+ name
351
+ }
352
+ }
353
+ }
354
+ }
355
+ }|
356
+
357
+ res = execute_query(query_string, context: { type_errors: log })
358
+ assert_equal nil, res["data"]["node"]
359
+ assert_equal [nil], log
360
+ end
361
+
362
+ def test_it_uses_type_error_hooks_for_failed_type_resolution
363
+ log = []
364
+ query_string = %|
365
+ {
366
+ node(id: "2003") {
367
+ __typename
368
+ }
369
+ }|
370
+
371
+ assert_raises(GraphQL::UnresolvedTypeError) {
372
+ execute_query(query_string, context: { type_errors: log })
373
+ }
374
+
375
+ assert_equal [SpecificationSchema::BOGUS_NODE], log
376
+ end
377
+
378
+ def test_it_treats_failed_type_resolution_like_nil
379
+ log = []
380
+ ctx = { type_errors: log, gobble: true }
381
+ query_string = %|
382
+ {
383
+ node(id: "2003") {
384
+ __typename
385
+ }
386
+ }|
387
+
388
+ res = execute_query(query_string, context: ctx)
389
+
390
+ assert_equal nil, res["data"]["node"]
391
+ assert_equal false, res.key?("errors")
392
+ assert_equal [SpecificationSchema::BOGUS_NODE], log
393
+
394
+ query_string_2 = %|
395
+ {
396
+ requiredNode(id: "2003") {
397
+ __typename
398
+ }
399
+ }|
400
+
401
+ res = execute_query(query_string_2, context: ctx)
402
+
403
+ assert_equal nil, res["data"]
404
+ assert_equal false, res.key?("errors")
405
+ assert_equal [SpecificationSchema::BOGUS_NODE, SpecificationSchema::BOGUS_NODE], log
406
+ end
486
407
  end
487
408
  end
488
409
  end