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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "graphql/compatibility/query_parser_specification/query_assertions"
2
3
  require "graphql/compatibility/query_parser_specification/parse_error_specification"
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Compatibility
3
4
  module QueryParserSpecification
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Compatibility
3
4
  module QueryParserSpecification
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Compatibility
3
4
  # This asserts that a given parse function turns a string into
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "graphql/define/assign_argument"
2
3
  require "graphql/define/assign_connection"
3
4
  require "graphql/define/assign_enum_value"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Define
3
4
  # Turn argument configs into a {GraphQL::Argument}.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Define
3
4
  module AssignConnection
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Define
3
4
  # Turn enum value configs into a {GraphQL::EnumType::EnumValue} and register it with the {GraphQL::EnumType}
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Define
3
4
  module AssignGlobalIdField
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Define
3
4
  # Turn field configs into a {GraphQL::Field} and attach it to a {GraphQL::ObjectType} or {GraphQL::InterfaceType}
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Define
3
4
  class DefinedObjectProxy
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Define
3
4
  # This module provides the `.define { ... }` API for
@@ -94,15 +95,19 @@ module GraphQL
94
95
  nil
95
96
  end
96
97
 
97
- # Make a new instance of this class, then
98
- # re-run any definitions on that object.
98
+ # Shallow-copy this object, then apply new definitions to the copy.
99
+ # @see {#define} for arguments
99
100
  # @return [InstanceDefinable] A new instance, with any extended definitions
100
101
  def redefine(**kwargs, &block)
101
102
  ensure_defined
102
- new_instance = self.class.new
103
- applied_definitions.each { |defn| new_instance.define(defn.define_keywords, &defn.define_proc) }
104
- new_instance.define(**kwargs, &block)
105
- new_instance
103
+ new_inst = self.dup
104
+ new_inst.define(**kwargs, &block)
105
+ new_inst
106
+ end
107
+
108
+ def initialize_copy(other)
109
+ super
110
+ @metadata = other.metadata.dup
106
111
  end
107
112
 
108
113
  private
@@ -125,16 +130,10 @@ module GraphQL
125
130
  if defn.define_proc
126
131
  defn_proxy.instance_eval(&defn.define_proc)
127
132
  end
128
-
129
- applied_definitions << defn
130
133
  end
131
134
  nil
132
135
  end
133
136
 
134
- def applied_definitions
135
- @applied_definitions ||= []
136
- end
137
-
138
137
  class Definition
139
138
  attr_reader :define_keywords, :define_proc
140
139
  def initialize(define_keywords, define_proc)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Define
3
4
  # Wrap the object in NonNullType in response to `!`
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Define
3
4
  # Some conveniences for definining return & argument types.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  # Directives are server-defined hooks for modifying execution.
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Directive::DeprecatedDirective = GraphQL::Directive.define do
2
3
  name "deprecated"
3
4
  description "Marks an element of a GraphQL schema as no longer supported."
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Directive::IncludeDirective = GraphQL::Directive.define do
2
3
  name "include"
3
4
  description "Directs the executor to include this field or fragment only when the `if` argument is true."
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GraphQL::Directive::SkipDirective = GraphQL::Directive.define do
2
3
  name "skip"
3
4
  description "Directs the executor to skip this field or fragment when the `if` argument is true."
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  # Represents a collection of related values.
3
4
  # By convention, enum names are `SCREAMING_CASE_NAMES`,
@@ -78,6 +79,12 @@ module GraphQL
78
79
  @values_by_name = {}
79
80
  end
80
81
 
82
+ def initialize_copy(other)
83
+ super
84
+ self.values = other.values.values
85
+ end
86
+
87
+
81
88
  # @param new_values [Array<EnumValue>] The set of values contained in this type
82
89
  def values=(new_values)
83
90
  @values_by_name = {}
@@ -104,7 +111,7 @@ module GraphQL
104
111
  matching_value = allowed_values.find { |v| v.name == value_name }
105
112
 
106
113
  if matching_value.nil?
107
- result.add_problem("Expected #{JSON.generate(value_name, quirks_mode: true)} to be one of: #{allowed_values.map(&:name).join(', ')}")
114
+ result.add_problem("Expected #{GraphQL::Language.serialize(value_name)} to be one of: #{allowed_values.map(&:name).join(', ')}")
108
115
  end
109
116
 
110
117
  result
@@ -1,2 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  require "graphql/execution/directive_checks"
3
+ require "graphql/execution/execute"
4
+ require "graphql/execution/field_result"
5
+ require "graphql/execution/lazy"
6
+ require "graphql/execution/selection_result"
2
7
  require "graphql/execution/typecast"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module Execution
3
4
  # Boolean checks for how an AST node's directives should
@@ -0,0 +1,222 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ module Execution
4
+ # A valid execution strategy
5
+ class Execute
6
+ PROPAGATE_NULL = :__graphql_propagate_null__
7
+
8
+ def execute(ast_operation, root_type, query)
9
+ result = resolve_selection(
10
+ query.root_value,
11
+ root_type,
12
+ query.irep_selection,
13
+ query.context,
14
+ mutation: query.mutation?
15
+ )
16
+
17
+ GraphQL::Execution::Lazy.resolve(result)
18
+
19
+ result.to_h
20
+ end
21
+
22
+ private
23
+
24
+ def resolve_selection(object, current_type, selection, query_ctx, mutation: false )
25
+ query = query_ctx.query
26
+
27
+ selection_result = SelectionResult.new
28
+
29
+ selection.each_selection(type: current_type) do |name, subselection|
30
+ field = query.get_field(current_type, subselection.definition_name)
31
+ field_result = resolve_field(
32
+ selection_result,
33
+ subselection,
34
+ current_type,
35
+ field,
36
+ object,
37
+ query_ctx
38
+ )
39
+
40
+ if mutation
41
+ GraphQL::Execution::Lazy.resolve(field_result)
42
+ end
43
+
44
+ selection_result.set(name, field_result)
45
+ end
46
+
47
+ selection_result
48
+ end
49
+
50
+ def resolve_field(owner, selection, parent_type, field, object, query_ctx)
51
+ query = query_ctx.query
52
+ field_ctx = query_ctx.spawn(
53
+ parent_type: parent_type,
54
+ field: field,
55
+ key: selection.name,
56
+ selection: selection,
57
+ )
58
+
59
+ arguments = query.arguments_for(selection.irep_node, field)
60
+ middlewares = query.schema.middleware
61
+ resolve_arguments = [parent_type, object, field, arguments, field_ctx]
62
+
63
+ raw_value = begin
64
+ # only run a middleware chain if there are any middleware
65
+ if middlewares.any?
66
+ chain = GraphQL::Schema::MiddlewareChain.new(
67
+ steps: middlewares + [FieldResolveStep],
68
+ arguments: resolve_arguments
69
+ )
70
+ chain.call
71
+ else
72
+ FieldResolveStep.call(*resolve_arguments)
73
+ end
74
+ rescue GraphQL::ExecutionError => err
75
+ err
76
+ end
77
+
78
+ result = if query.schema.lazy?(raw_value)
79
+ field.prepare_lazy(raw_value, arguments, field_ctx).then { |inner_value|
80
+ continue_resolve_field(selection, parent_type, field, inner_value, field_ctx)
81
+ }
82
+ elsif raw_value.is_a?(GraphQL::Execution::Lazy)
83
+ # It came from a connection resolve, assume it was already instrumented
84
+ raw_value.then { |inner_value|
85
+ continue_resolve_field(selection, parent_type, field, inner_value, field_ctx)
86
+ }
87
+ else
88
+ continue_resolve_field(selection, parent_type, field, raw_value, field_ctx)
89
+ end
90
+
91
+ FieldResult.new(
92
+ owner: owner,
93
+ field: field,
94
+ value: result,
95
+ )
96
+ end
97
+
98
+ def continue_resolve_field(selection, parent_type, field, raw_value, field_ctx)
99
+ query = field_ctx.query
100
+
101
+ case raw_value
102
+ when GraphQL::ExecutionError
103
+ raw_value.ast_node = field_ctx.ast_node
104
+ raw_value.path = field_ctx.path
105
+ query.context.errors.push(raw_value)
106
+ when Array
107
+ list_errors = raw_value.each_with_index.select { |value, _| value.is_a?(GraphQL::ExecutionError) }
108
+ if list_errors.any?
109
+ list_errors.each do |error, index|
110
+ error.ast_node = field_ctx.ast_node
111
+ error.path = field_ctx.path + [index]
112
+ query.context.errors.push(error)
113
+ end
114
+ end
115
+ end
116
+
117
+ resolve_value(
118
+ parent_type,
119
+ field,
120
+ field.type,
121
+ raw_value,
122
+ selection,
123
+ field_ctx,
124
+ )
125
+ end
126
+
127
+ def resolve_value(parent_type, field_defn, field_type, value, selection, field_ctx)
128
+ if value.nil?
129
+ if field_type.kind.non_null?
130
+ type_error = GraphQL::InvalidNullError.new(parent_type, field_defn, value)
131
+ field_ctx.schema.type_error(type_error, field_ctx)
132
+ PROPAGATE_NULL
133
+ else
134
+ nil
135
+ end
136
+ elsif value.is_a?(GraphQL::ExecutionError)
137
+ if field_type.kind.non_null?
138
+ PROPAGATE_NULL
139
+ else
140
+ nil
141
+ end
142
+ else
143
+ case field_type.kind
144
+ when GraphQL::TypeKinds::SCALAR
145
+ field_type.coerce_result(value)
146
+ when GraphQL::TypeKinds::ENUM
147
+ field_type.coerce_result(value, field_ctx.query.warden)
148
+ when GraphQL::TypeKinds::LIST
149
+ wrapped_type = field_type.of_type
150
+ i = 0
151
+ result = []
152
+ value.each do |inner_value|
153
+ inner_ctx = field_ctx.spawn(
154
+ key: i,
155
+ selection: selection,
156
+ parent_type: parent_type,
157
+ field: field_defn,
158
+ )
159
+
160
+ result << resolve_value(
161
+ parent_type,
162
+ field_defn,
163
+ wrapped_type,
164
+ inner_value,
165
+ selection,
166
+ inner_ctx,
167
+ )
168
+ i += 1
169
+ end
170
+ result
171
+ when GraphQL::TypeKinds::NON_NULL
172
+ wrapped_type = field_type.of_type
173
+ inner_value = resolve_value(
174
+ parent_type,
175
+ field_defn,
176
+ wrapped_type,
177
+ value,
178
+ selection,
179
+ field_ctx,
180
+ )
181
+ when GraphQL::TypeKinds::OBJECT
182
+ resolve_selection(
183
+ value,
184
+ field_type,
185
+ selection,
186
+ field_ctx
187
+ )
188
+ when GraphQL::TypeKinds::UNION, GraphQL::TypeKinds::INTERFACE
189
+ query = field_ctx.query
190
+ resolved_type = query.resolve_type(value)
191
+ possible_types = query.possible_types(field_type)
192
+
193
+ if !possible_types.include?(resolved_type)
194
+ type_error = GraphQL::UnresolvedTypeError.new(value, field_defn, parent_type, resolved_type, possible_types)
195
+ field_ctx.schema.type_error(type_error, field_ctx)
196
+ PROPAGATE_NULL
197
+ else
198
+ resolve_value(
199
+ parent_type,
200
+ field_defn,
201
+ resolved_type,
202
+ value,
203
+ selection,
204
+ field_ctx,
205
+ )
206
+ end
207
+ else
208
+ raise("Unknown type kind: #{field_type.kind}")
209
+ end
210
+ end
211
+ end
212
+
213
+ # A `.call`-able suitable to be the last step in a middleware chain
214
+ module FieldResolveStep
215
+ # Execute the field's resolve method
216
+ def self.call(_parent_type, parent_object, field_definition, field_args, context, _next = nil)
217
+ field_definition.resolve(parent_object, field_args, context)
218
+ end
219
+ end
220
+ end
221
+ end
222
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ module Execution
4
+ # This is one key-value pair in a GraphQL response.
5
+ class FieldResult
6
+ # @return [Any, Lazy] the GraphQL-ready response value, or a {Lazy} instance
7
+ attr_reader :value
8
+
9
+ # @return [GraphQL::Field] The field which resolved this value
10
+ attr_reader :field
11
+
12
+ # @return [SelectionResult] The result object that this field belongs to
13
+ attr_reader :owner
14
+
15
+ def initialize(field:, value:, owner:)
16
+ @field = field
17
+ @owner = owner
18
+ self.value = value
19
+ end
20
+
21
+ # Set a new value for this field in the response.
22
+ # It may be updated after resolving a {Lazy}.
23
+ # If it is {Execute::PROPAGATE_NULL}, tell the owner to propagate null.
24
+ # If the value is a {SelectionResult}, make a link with it, and if it's already null,
25
+ # propagate the null as needed.
26
+ # @param new_value [Any] The GraphQL-ready value
27
+ def value=(new_value)
28
+ if new_value.is_a?(SelectionResult)
29
+ if new_value.invalid_null?
30
+ new_value = GraphQL::Execution::Execute::PROPAGATE_NULL
31
+ else
32
+ new_value.owner = self
33
+ end
34
+ end
35
+
36
+ if new_value == GraphQL::Execution::Execute::PROPAGATE_NULL
37
+ if field.type.kind.non_null?
38
+ @owner.propagate_null
39
+ else
40
+ @value = nil
41
+ end
42
+ else
43
+ @value = new_value
44
+ end
45
+ end
46
+
47
+ def inspect
48
+ "#<FieldResult #{value.inspect} (#{field.type})>"
49
+ end
50
+ end
51
+ end
52
+ end