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
@@ -0,0 +1,14 @@
1
+ module GraphQL
2
+ class Schema
3
+ # @api private
4
+ module Base64Encoder
5
+ def self.encode(plaintext, nonce: false)
6
+ Base64.strict_encode64(plaintext)
7
+ end
8
+
9
+ def self.decode(ciphertext, nonce: false)
10
+ Base64.decode64(ciphertext)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  module BuildFromDefinition
@@ -84,6 +85,8 @@ module GraphQL
84
85
  raise(NotImplementedError, "Generated Schema cannot use Interface or Union types for execution.")
85
86
  }
86
87
 
88
+ NullScalarCoerce = ->(val) { val }
89
+
87
90
  def build_enum_type(enum_type_definition, type_resolver)
88
91
  GraphQL::EnumType.define(
89
92
  name: enum_type_definition.name,
@@ -113,6 +116,7 @@ module GraphQL
113
116
  GraphQL::ScalarType.define(
114
117
  name: scalar_type_definition.name,
115
118
  description: scalar_type_definition.description,
119
+ coerce: NullScalarCoerce,
116
120
  )
117
121
  end
118
122
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  # In early GraphQL versions, errors would be "automatically"
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module GraphQL
3
+ class Schema
4
+ module DefaultTypeError
5
+ def self.call(type_error, ctx)
6
+ case type_error
7
+ when GraphQL::InvalidNullError
8
+ ctx.errors << type_error
9
+ when GraphQL::UnresolvedTypeError
10
+ raise type_error
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  # A two-level map with fields as the last values.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  class InvalidTypeError < GraphQL::Error
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  # You can use the result of {GraphQL::Introspection::INTROSPECTION_QUERY}
@@ -36,6 +37,8 @@ module GraphQL
36
37
  raise(NotImplementedError, "This schema was loaded from string, so it can't resolve types for objects")
37
38
  }
38
39
 
40
+ NullScalarCoerce = ->(val) { val }
41
+
39
42
  class << self
40
43
  private
41
44
 
@@ -119,7 +122,8 @@ module GraphQL
119
122
  else
120
123
  ScalarType.define(
121
124
  name: type["name"],
122
- description: type["description"]
125
+ description: type["description"],
126
+ coerce: NullScalarCoerce,
123
127
  )
124
128
  end
125
129
  when "UNION"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  # Given {steps} and {arguments}, call steps in order, passing `(*arguments, next_step)`.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  # Find the members of a union or interface within a given schema.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  # Used to convert your {GraphQL::Schema} to a GraphQL schema string
@@ -95,7 +96,7 @@ module GraphQL
95
96
  def print_description(definition, indentation='', first_in_block=true)
96
97
  return '' unless definition.description
97
98
 
98
- description = indentation != '' && !first_in_block ? "\n" : ""
99
+ description = indentation != '' && !first_in_block ? "\n".dup : "".dup
99
100
  description << GraphQL::Language::Comments.commentize(definition.description, indent: indentation)
100
101
  end
101
102
  end
@@ -111,7 +112,7 @@ module GraphQL
111
112
  return "(#{field_arguments.map{ |arg| print_input_value(arg) }.join(", ")})"
112
113
  end
113
114
 
114
- out = "(\n"
115
+ out = "(\n".dup
115
116
  out << field_arguments.map.with_index{ |arg, i|
116
117
  "#{print_description(arg, " #{indentation}", i == 0)} #{indentation}"\
117
118
  "#{print_input_value(arg)}"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  module ReduceTypes
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  # - Store a table of errors & handlers
@@ -14,7 +15,7 @@ module GraphQL
14
15
  # @example Rescue from not-found by telling the user
15
16
  # MySchema.rescue_from(ActiveRecord::RecordNotFound) { "An item could not be found" }
16
17
  #
17
- # @param [Class] a class of error to rescue from
18
+ # @param error_class [Class] a class of error to rescue from
18
19
  # @yield [err] A handler to return a message for this error instance
19
20
  # @yieldparam [Exception] an error that was rescued
20
21
  # @yieldreturn [String] message to put in GraphQL response
@@ -23,7 +24,7 @@ module GraphQL
23
24
  end
24
25
 
25
26
  # Remove the handler for `error_class`
26
- # @param [Class] the error class whose handler should be removed
27
+ # @param error_class [Class] the error class whose handler should be removed
27
28
  def remove_handler(error_class)
28
29
  rescue_table.delete(error_class)
29
30
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "delegate"
2
3
 
3
4
  module GraphQL
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  module TypeExpression
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  # Stores `{ name => type }` pairs for a given schema.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  module UniqueWithinType
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  # This module provides a function for validating GraphQL types.
@@ -86,7 +87,6 @@ module GraphQL
86
87
  }
87
88
  end
88
89
 
89
-
90
90
  FIELDS_ARE_VALID = Rules.assert_named_items_are_valid("field", ->(type) { type.all_fields })
91
91
 
92
92
  HAS_ONE_OR_MORE_POSSIBLE_TYPES = ->(type) {
@@ -155,6 +155,47 @@ module GraphQL
155
155
  # :ok_hand:
156
156
  end
157
157
  }
158
+
159
+ SCHEMA_INSTRUMENTERS_ARE_VALID = ->(schema) {
160
+ errs = []
161
+ schema.instrumenters[:query].each do |inst|
162
+ if !inst.respond_to?(:before_query) || !inst.respond_to?(:after_query)
163
+ errs << "`instrument(:query, #{inst})` is invalid: must respond to `before_query(query)` and `after_query(query)` "
164
+ end
165
+ end
166
+
167
+ schema.instrumenters[:field].each do |inst|
168
+ if !inst.respond_to?(:instrument)
169
+ errs << "`instrument(:field, #{inst})` is invalid: must respond to `instrument(type, field)`"
170
+ end
171
+ end
172
+
173
+ if errs.any?
174
+ errs.join("Invalid instrumenters:\n" + errs.join("\n"))
175
+ else
176
+ nil
177
+ end
178
+ }
179
+
180
+ RESERVED_TYPE_NAME = ->(type) {
181
+ if type.name.start_with?('__') && INTROSPECTION_TYPES[type.name] != type
182
+ # TODO: make this a hard failure in a later version
183
+ warn("Name #{type.name.inspect} must not begin with \"__\", which is reserved by GraphQL introspection.")
184
+ nil
185
+ else
186
+ # ok name
187
+ end
188
+ }
189
+
190
+ RESERVED_NAME = ->(named_thing) {
191
+ if named_thing.name.start_with?('__')
192
+ # TODO: make this a hard failure in a later version
193
+ warn("Name #{named_thing.name.inspect} must not begin with \"__\", which is reserved by GraphQL introspection.")
194
+ nil
195
+ else
196
+ # no worries
197
+ end
198
+ }
158
199
  end
159
200
 
160
201
  # A mapping of `{Class => [Proc, Proc...]}` pairs.
@@ -163,6 +204,7 @@ module GraphQL
163
204
  RULES = {
164
205
  GraphQL::Field => [
165
206
  Rules::NAME_IS_STRING,
207
+ Rules::RESERVED_NAME,
166
208
  Rules::DESCRIPTION_IS_STRING_OR_NIL,
167
209
  Rules.assert_property(:deprecation_reason, String, NilClass),
168
210
  Rules.assert_property(:type, GraphQL::BaseType),
@@ -172,12 +214,14 @@ module GraphQL
172
214
  ],
173
215
  GraphQL::Argument => [
174
216
  Rules::NAME_IS_STRING,
217
+ Rules::RESERVED_NAME,
175
218
  Rules::DESCRIPTION_IS_STRING_OR_NIL,
176
219
  Rules::TYPE_IS_VALID_INPUT_TYPE,
177
220
  Rules::DEFAULT_VALUE_IS_VALID_FOR_TYPE,
178
221
  ],
179
222
  GraphQL::BaseType => [
180
223
  Rules::NAME_IS_STRING,
224
+ Rules::RESERVED_TYPE_NAME,
181
225
  Rules::DESCRIPTION_IS_STRING_OR_NIL,
182
226
  ],
183
227
  GraphQL::ObjectType => [
@@ -199,8 +243,20 @@ module GraphQL
199
243
  Rules::SCHEMA_CAN_RESOLVE_TYPES,
200
244
  Rules::SCHEMA_CAN_FETCH_IDS,
201
245
  Rules::SCHEMA_CAN_GENERATE_IDS,
246
+ Rules::SCHEMA_INSTRUMENTERS_ARE_VALID,
202
247
  ],
203
248
  }
249
+
250
+ INTROSPECTION_TYPES = Hash[[
251
+ GraphQL::Introspection::TypeType,
252
+ GraphQL::Introspection::TypeKindEnum,
253
+ GraphQL::Introspection::FieldType,
254
+ GraphQL::Introspection::InputValueType,
255
+ GraphQL::Introspection::EnumValueType,
256
+ GraphQL::Introspection::DirectiveType,
257
+ GraphQL::Introspection::DirectiveLocationEnum,
258
+ GraphQL::Introspection::SchemaType,
259
+ ].map{ |type| [type.name, type] }]
204
260
  end
205
261
  end
206
262
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  class Schema
3
4
  # Restrict access to a {GraphQL::Schema} with a user-defined mask.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "graphql/static_validation/message"
2
3
  require "graphql/static_validation/arguments_validator"
3
4
  require "graphql/static_validation/type_stack"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  # Default rules for {GraphQL::StaticValidation::Validator}
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  # Implement validate_node
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  # Test whether `ast_value` is a valid input for `type`
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  # Generates GraphQL-compliant validation message.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class ArgumentLiteralsAreCompatible < GraphQL::StaticValidation::ArgumentsValidator
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class ArgumentsAreDefined < GraphQL::StaticValidation::ArgumentsValidator
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class DirectivesAreDefined
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class DirectivesAreInValidLocations
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class FieldsAreDefinedOnType
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  # Scalars _can't_ have selections
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class FieldsWillMerge
@@ -76,7 +77,7 @@ module GraphQL
76
77
 
77
78
  args = defs.map { |defn| reduce_list(defn.arguments)}.uniq
78
79
  if args.length != 1
79
- errors << message("Field '#{name}' has an argument conflict: #{args.map {|a| print_arg(a) }.join(" or ")}?", defs.first, context: context)
80
+ errors << message("Field '#{name}' has an argument conflict: #{args.map{ |arg| GraphQL::Language.serialize(arg) }.join(" or ")}?", defs.first, context: context)
80
81
  end
81
82
 
82
83
  @errors = errors
@@ -88,8 +89,10 @@ module GraphQL
88
89
  case arg
89
90
  when GraphQL::Language::Nodes::VariableIdentifier
90
91
  "$#{arg.name}"
92
+ when GraphQL::Language::Nodes::Enum
93
+ "#{arg.name}"
91
94
  else
92
- JSON.dump(arg)
95
+ GraphQL::Language.serialize(arg)
93
96
  end
94
97
  end
95
98
 
@@ -97,7 +100,7 @@ module GraphQL
97
100
  # can't look up args, the names just have to match
98
101
  def reduce_list(args)
99
102
  args.reduce({}) do |memo, a|
100
- memo[a.name] = NAMED_VALUES.include?(a.value.class) ? a.value.name : a.value
103
+ memo[a.name] = print_arg(a.value)
101
104
  memo
102
105
  end
103
106
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class FragmentSpreadsArePossible
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class FragmentTypesExist
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class FragmentsAreFinite
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class FragmentsAreNamed
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class FragmentsAreOnCompositeTypes
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class FragmentsAreUsed
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module GraphQL
2
3
  module StaticValidation
3
4
  class MutationRootExists