graphql 1.2.6 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  # An Interface contains a collection of types which implement some of the same fields.
3
4
  #
@@ -31,6 +32,11 @@ module GraphQL
31
32
  @fields = {}
32
33
  end
33
34
 
35
+ def initialize_copy(other)
36
+ super
37
+ @fields = other.fields.dup
38
+ end
39
+
34
40
  def kind
35
41
  GraphQL::TypeKinds::INTERFACE
36
42
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "graphql/internal_representation/node"
2
3
  require "graphql/internal_representation/rewrite"
3
- require "graphql/internal_representation/selections"
4
+ require "graphql/internal_representation/selection"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "set"
2
3
 
3
4
  module GraphQL
@@ -114,7 +115,7 @@ module GraphQL
114
115
 
115
116
  def inspect(indent = 0)
116
117
  own_indent = " " * indent
117
- self_inspect = "#{own_indent}<Node #{name} #{skipped? ? "(skipped)" : ""}(#{definition_name} -> #{return_type})>"
118
+ self_inspect = "#{own_indent}<Node #{name} #{skipped? ? "(skipped)" : ""}(#{definition_name} -> #{return_type})>".dup
118
119
  if typed_children.any?
119
120
  self_inspect << " {"
120
121
  typed_children.each do |type_defn, children|
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module InternalRepresentation
3
4
  # Convert an AST into a tree of {InternalRepresentation::Node}s
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ module InternalRepresentation
4
+ # A selection is a single field on an object.
5
+ # It's "backed" by one or more {Node}s.
6
+ class Selection
7
+ def initialize(query:, nodes:)
8
+ @irep_node = nodes.first
9
+ @definition_name = @irep_node.definition_name
10
+ @name = @irep_node.name
11
+
12
+ @skipped = nodes.any?(&:skipped?)
13
+ @query = query
14
+ @typed_child_nodes = build_typed_selections(query, nodes)
15
+ @typed_subselections = Hash.new { |h, k| h[k] = {} }
16
+ end
17
+
18
+ # @return [String] name of the field in this selection
19
+ attr_reader :definition_name
20
+
21
+ # @return [String] the key of this selection in the result (may be the field's alias)
22
+ attr_reader :name
23
+
24
+ # @return [Node] A "representative" node for this selection. Legacy. In the case that a selection appears in multiple nodes, is this valuable?
25
+ attr_reader :irep_node
26
+
27
+ # @return [Boolean] true if _any_ of the backing nodes are skipped
28
+ def skipped?
29
+ @skipped
30
+ end
31
+
32
+ # Call the block with each name & subselection whose conditions match `type`
33
+ # @param type [GraphQL::BaseType] The type to get selections on
34
+ # @yieldparam name [String] the key in the child selection
35
+ # @yieldparam subselection [Selection] the selection for that key
36
+ def each_selection(type:)
37
+ subselections = @typed_subselections[type]
38
+ @typed_child_nodes[type].each do |name, child_nodes|
39
+ subselection = subselections[name] ||= self.class.new(query: @query, nodes: child_nodes)
40
+ if !subselection.skipped?
41
+ yield(name, subselection)
42
+ end
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ # Turn `nodes` into a two-dimensional hash, based on type information from `query`
49
+ # @return [Hash] A 2d mapping of `{ type => { name => nodes } }`
50
+ def build_typed_selections(query, nodes)
51
+ selections = Hash.new { |h,k| h[k] = Hash.new { |h2, k2| h2[k2] = [] } }
52
+
53
+ object_types = Set.new
54
+
55
+ warden = query.warden
56
+ ctx = query.context
57
+
58
+ # Find the object types which are possible among typed children
59
+ nodes.each do |node|
60
+ node.typed_children.each_key do |type_cond|
61
+ object_types.merge(warden.possible_types(type_cond))
62
+ end
63
+ end
64
+
65
+ # For each object types, find the irep_nodes
66
+ # which may apply to it, then add the children
67
+ # of that node to this object's children
68
+ nodes.each do |node|
69
+ node.typed_children.each do |type_cond, children|
70
+ object_types.each do |obj_type|
71
+ obj_selections = selections[obj_type]
72
+ if GraphQL::Execution::Typecast.compatible?(obj_type, type_cond, ctx)
73
+ children.each do |name, irep_node|
74
+ obj_selections[name] << irep_node
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ selections
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Introspection
3
4
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::ArgumentsField = GraphQL::Field.define do
2
3
  type !GraphQL::ListType.new(of_type: !GraphQL::Introspection::InputValueType)
3
4
  resolve ->(obj, args, ctx) {
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::DirectiveLocationEnum = GraphQL::EnumType.define do
2
3
  name "__DirectiveLocation"
3
4
  description "A Directive can be adjacent to many parts of the GraphQL language, a "\
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::DirectiveType = GraphQL::ObjectType.define do
2
3
  name "__Directive"
3
4
  description "A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document."\
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::EnumValueType = GraphQL::ObjectType.define do
2
3
  name "__EnumValue"
3
4
  description "One possible value for a given Enum. Enum values are unique values, not a "\
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::EnumValuesField = GraphQL::Field.define do
2
3
  type types[!GraphQL::Introspection::EnumValueType]
3
4
  argument :includeDeprecated, types.Boolean, default_value: false
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::FieldType = GraphQL::ObjectType.define do
2
3
  name "__Field"
3
4
  description "Object and Interface types are described by a list of Fields, each of which has "\
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::FieldsField = GraphQL::Field.define do
2
3
  type -> { types[!GraphQL::Introspection::FieldType] }
3
4
  argument :includeDeprecated, GraphQL::BOOLEAN_TYPE, default_value: false
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::InputFieldsField = GraphQL::Field.define do
2
3
  name "inputFields"
3
4
  type types[!GraphQL::Introspection::InputValueType]
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::InputValueType = GraphQL::ObjectType.define do
2
3
  name "__InputValue"
3
4
  description "Arguments provided to Fields or Directives and the input fields of an "\
@@ -10,7 +11,7 @@ GraphQL::Introspection::InputValueType = GraphQL::ObjectType.define do
10
11
  resolve ->(obj, args, ctx) {
11
12
  if obj.default_value?
12
13
  value = obj.default_value
13
- value.nil? ? 'null' : JSON.generate(obj.type.coerce_result(value), quirks_mode: true)
14
+ value.nil? ? 'null' : GraphQL::Language.serialize(obj.type.coerce_result(value))
14
15
  else
15
16
  nil
16
17
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::InterfacesField = GraphQL::Field.define do
2
3
  type -> { types[!GraphQL::Introspection::TypeType] }
3
4
  resolve ->(target, a, ctx) {
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # The introspection query to end all introspection queries, copied from
2
3
  # https://github.com/graphql/graphql-js/blob/master/src/utilities/introspectionQuery.js
3
4
  GraphQL::Introspection::INTROSPECTION_QUERY = "
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::OfTypeField = GraphQL::Field.define do
2
3
  name "ofType"
3
4
  type -> { GraphQL::Introspection::TypeType }
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::PossibleTypesField = GraphQL::Field.define do
2
3
  type -> { types[!GraphQL::Introspection::TypeType] }
3
4
  resolve ->(target, args, ctx) {
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Introspection
3
4
  # A wrapper to implement `__schema`
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::SchemaType = GraphQL::ObjectType.define do
2
3
  name "__Schema"
3
4
  description "A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all "\
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Introspection
3
4
  # A wrapper to create `__type(name: )` dynamically.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::TypeKindEnum = GraphQL::EnumType.define do
2
3
  name "__TypeKind"
3
4
  description "An enum describing what kind of type a given `__Type` is."
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Introspection::TypeType = GraphQL::ObjectType.define do
2
3
  name "__Type"
3
4
  description "The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in "\
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Introspection
3
4
  # A wrapper to create `__typename`.
@@ -1,12 +1,22 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  # Raised automatically when a field's resolve function returns `nil`
3
4
  # for a non-null field.
4
- class InvalidNullError < GraphQL::Error
5
- def initialize(parent_type_name, field_name, value)
6
- @parent_type_name = parent_type_name
7
- @field_name = field_name
5
+ class InvalidNullError < GraphQL::RuntimeTypeError
6
+ # @return [GraphQL::BaseType] The owner of {#field}
7
+ attr_reader :parent_type
8
+
9
+ # @return [GraphQL::Field] The field which failed to return a value
10
+ attr_reader :field
11
+
12
+ # @return [nil, GraphQL::ExecutionError] The invalid value for this field
13
+ attr_reader :value
14
+
15
+ def initialize(parent_type, field, value)
16
+ @parent_type = parent_type
17
+ @field = field
8
18
  @value = value
9
- super("Cannot return null for non-nullable field #{@parent_type_name}.#{@field_name}")
19
+ super("Cannot return null for non-nullable field #{@parent_type.name}.#{@field.name}")
10
20
  end
11
21
 
12
22
  # @return [Hash] An entry for the response's "errors" key
@@ -14,9 +24,9 @@ module GraphQL
14
24
  { "message" => message }
15
25
  end
16
26
 
17
- # @return [Boolean] Whether the null in question was caused by another error
27
+ # @deprecated always false
18
28
  def parent_error?
19
- @value.is_a?(GraphQL::ExecutionError)
29
+ false
20
30
  end
21
31
  end
22
32
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "graphql/language/definition_slice"
2
3
  require "graphql/language/generation"
3
4
  require "graphql/language/lexer"
@@ -6,3 +7,12 @@ require "graphql/language/parser"
6
7
  require "graphql/language/token"
7
8
  require "graphql/language/visitor"
8
9
  require "graphql/language/comments"
10
+
11
+ module GraphQL
12
+ module Language
13
+ # @api private
14
+ def self.serialize(value)
15
+ JSON.generate(value, quirks_mode: true)
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Language
3
4
  module Comments
@@ -6,7 +7,7 @@ module GraphQL
6
7
  def commentize(description, indent: '')
7
8
  lines = description.split("\n")
8
9
 
9
- comment = ''
10
+ comment = ''.dup
10
11
 
11
12
  lines.each do |line|
12
13
  if line == ''
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Language
3
4
  module DefinitionSlice
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Language
3
4
  # Exposes {.generate}, which turns AST nodes back into query strings.
@@ -19,17 +20,17 @@ module GraphQL
19
20
  when Nodes::Document
20
21
  node.definitions.map { |d| generate(d) }.join("\n\n")
21
22
  when Nodes::Argument
22
- "#{node.name}: #{generate(node.value)}"
23
+ "#{node.name}: #{generate(node.value)}".dup
23
24
  when Nodes::Directive
24
- out = "@#{node.name}"
25
+ out = "@#{node.name}".dup
25
26
  out << "(#{node.arguments.map { |a| generate(a) }.join(", ")})" if node.arguments.any?
26
27
  out
27
28
  when Nodes::Enum
28
- "#{node.name}"
29
+ "#{node.name}".dup
29
30
  when Nodes::NullValue
30
- "null"
31
+ "null".dup
31
32
  when Nodes::Field
32
- out = "#{indent}"
33
+ out = "#{indent}".dup
33
34
  out << "#{node.alias}: " if node.alias
34
35
  out << "#{node.name}"
35
36
  out << "(#{node.arguments.map { |a| generate(a) }.join(", ")})" if node.arguments.any?
@@ -37,7 +38,7 @@ module GraphQL
37
38
  out << generate_selections(node.selections, indent: indent)
38
39
  out
39
40
  when Nodes::FragmentDefinition
40
- out = "#{indent}fragment #{node.name}"
41
+ out = "#{indent}fragment #{node.name}".dup
41
42
  if node.type
42
43
  out << " on #{generate(node.type)}"
43
44
  end
@@ -45,11 +46,11 @@ module GraphQL
45
46
  out << generate_selections(node.selections, indent: indent)
46
47
  out
47
48
  when Nodes::FragmentSpread
48
- out = "#{indent}...#{node.name}"
49
+ out = "#{indent}...#{node.name}".dup
49
50
  out << generate_directives(node.directives)
50
51
  out
51
52
  when Nodes::InlineFragment
52
- out = "#{indent}..."
53
+ out = "#{indent}...".dup
53
54
  if node.type
54
55
  out << " on #{generate(node.type)}"
55
56
  end
@@ -59,24 +60,24 @@ module GraphQL
59
60
  when Nodes::InputObject
60
61
  generate(node.to_h)
61
62
  when Nodes::ListType
62
- "[#{generate(node.of_type)}]"
63
+ "[#{generate(node.of_type)}]".dup
63
64
  when Nodes::NonNullType
64
- "#{generate(node.of_type)}!"
65
+ "#{generate(node.of_type)}!".dup
65
66
  when Nodes::OperationDefinition
66
- out = "#{indent}#{node.operation_type}"
67
+ out = "#{indent}#{node.operation_type}".dup
67
68
  out << " #{node.name}" if node.name
68
69
  out << "(#{node.variables.map { |v| generate(v) }.join(", ")})" if node.variables.any?
69
70
  out << generate_directives(node.directives)
70
71
  out << generate_selections(node.selections, indent: indent)
71
72
  out
72
73
  when Nodes::TypeName
73
- "#{node.name}"
74
+ "#{node.name}".dup
74
75
  when Nodes::VariableDefinition
75
- out = "$#{node.name}: #{generate(node.type)}"
76
+ out = "$#{node.name}: #{generate(node.type)}".dup
76
77
  out << " = #{generate(node.default_value)}" unless node.default_value.nil?
77
78
  out
78
79
  when Nodes::VariableIdentifier
79
- "$#{node.name}"
80
+ "$#{node.name}".dup
80
81
  when Nodes::SchemaDefinition
81
82
  if (node.query.nil? || node.query == 'Query') &&
82
83
  (node.mutation.nil? || node.mutation == 'Mutation') &&
@@ -84,7 +85,7 @@ module GraphQL
84
85
  return
85
86
  end
86
87
 
87
- out = "schema {\n"
88
+ out = "schema {\n".dup
88
89
  out << " query: #{node.query}\n" if node.query
89
90
  out << " mutation: #{node.mutation}\n" if node.mutation
90
91
  out << " subscription: #{node.subscription}\n" if node.subscription
@@ -100,7 +101,7 @@ module GraphQL
100
101
  out << " implements " << node.interfaces.map(&:name).join(", ") unless node.interfaces.empty?
101
102
  out << generate_field_definitions(node.fields)
102
103
  when Nodes::InputValueDefinition
103
- out = "#{node.name}: #{generate(node.type)}"
104
+ out = "#{node.name}: #{generate(node.type)}".dup
104
105
  out << " = #{generate(node.default_value)}" unless node.default_value.nil?
105
106
  out << generate_directives(node.directives)
106
107
  when Nodes::FieldDefinition
@@ -129,7 +130,7 @@ module GraphQL
129
130
  end
130
131
  out << "}"
131
132
  when Nodes::EnumValueDefinition
132
- out = " #{node.name}"
133
+ out = " #{node.name}".dup
133
134
  out << generate_directives(node.directives)
134
135
  out << "\n"
135
136
  when Nodes::InputObjectTypeDefinition
@@ -150,11 +151,11 @@ module GraphQL
150
151
  when Nodes::AbstractNode
151
152
  node.to_query_string(indent: indent)
152
153
  when FalseClass, Float, Integer, NilClass, String, TrueClass
153
- JSON.generate(node, quirks_mode: true)
154
+ GraphQL::Language.serialize(node)
154
155
  when Array
155
- "[#{node.map { |v| generate(v) }.join(", ")}]"
156
+ "[#{node.map { |v| generate(v) }.join(", ")}]".dup
156
157
  when Hash
157
- "{#{node.map { |k, v| "#{k}: #{generate(v)}" }.join(", ")}}"
158
+ "{#{node.map { |k, v| "#{k}: #{generate(v)}" }.join(", ")}}".dup
158
159
  else
159
160
  raise TypeError
160
161
  end
@@ -172,7 +173,7 @@ module GraphQL
172
173
 
173
174
  def generate_selections(selections, indent: "")
174
175
  if selections.any?
175
- out = " {\n"
176
+ out = " {\n".dup
176
177
  selections.each do |selection|
177
178
  out << generate(selection, indent: indent + " ") << "\n"
178
179
  end
@@ -183,14 +184,14 @@ module GraphQL
183
184
  end
184
185
 
185
186
  def generate_description(node, indent: '', first_in_block: true)
186
- return '' unless node.description
187
+ return ''.dup unless node.description
187
188
 
188
- description = indent != '' && !first_in_block ? "\n" : ""
189
+ description = indent != '' && !first_in_block ? "\n".dup : "".dup
189
190
  description << GraphQL::Language::Comments.commentize(node.description, indent: indent)
190
191
  end
191
192
 
192
193
  def generate_field_definitions(fields)
193
- out = " {\n"
194
+ out = " {\n".dup
194
195
  fields.each.with_index do |field, i|
195
196
  out << generate_description(field, indent: ' ', first_in_block: i == 0)
196
197
  out << " #{generate(field)}\n"