graphql 1.13.17 → 2.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/install_generator.rb +1 -1
  3. data/lib/generators/graphql/relay.rb +3 -17
  4. data/lib/generators/graphql/templates/schema.erb +3 -0
  5. data/lib/graphql/analysis/ast/field_usage.rb +3 -1
  6. data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
  7. data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
  8. data/lib/graphql/analysis/ast/query_depth.rb +0 -1
  9. data/lib/graphql/analysis/ast/visitor.rb +43 -36
  10. data/lib/graphql/analysis/ast.rb +2 -12
  11. data/lib/graphql/analysis.rb +0 -7
  12. data/lib/graphql/backtrace/table.rb +2 -20
  13. data/lib/graphql/backtrace/tracer.rb +2 -3
  14. data/lib/graphql/backtrace.rb +2 -8
  15. data/lib/graphql/dataloader/null_dataloader.rb +3 -1
  16. data/lib/graphql/dataloader/source.rb +9 -0
  17. data/lib/graphql/dataloader.rb +4 -1
  18. data/lib/graphql/dig.rb +1 -1
  19. data/lib/graphql/execution/errors.rb +12 -82
  20. data/lib/graphql/execution/interpreter/resolve.rb +26 -0
  21. data/lib/graphql/execution/interpreter/runtime.rb +159 -120
  22. data/lib/graphql/execution/interpreter.rb +187 -78
  23. data/lib/graphql/execution/lazy.rb +7 -21
  24. data/lib/graphql/execution/lookahead.rb +44 -40
  25. data/lib/graphql/execution/multiplex.rb +3 -174
  26. data/lib/graphql/execution.rb +11 -4
  27. data/lib/graphql/introspection/directive_type.rb +2 -2
  28. data/lib/graphql/introspection/dynamic_fields.rb +3 -8
  29. data/lib/graphql/introspection/entry_points.rb +2 -15
  30. data/lib/graphql/introspection/field_type.rb +1 -1
  31. data/lib/graphql/introspection/schema_type.rb +2 -2
  32. data/lib/graphql/introspection/type_type.rb +13 -6
  33. data/lib/graphql/introspection.rb +4 -3
  34. data/lib/graphql/language/document_from_schema_definition.rb +18 -35
  35. data/lib/graphql/language/lexer.rb +216 -1488
  36. data/lib/graphql/language/nodes.rb +65 -39
  37. data/lib/graphql/language/parser.rb +376 -364
  38. data/lib/graphql/language/parser.y +49 -44
  39. data/lib/graphql/language/printer.rb +37 -21
  40. data/lib/graphql/language/visitor.rb +191 -83
  41. data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
  42. data/lib/graphql/pagination/array_connection.rb +4 -2
  43. data/lib/graphql/pagination/connection.rb +31 -4
  44. data/lib/graphql/pagination/connections.rb +3 -28
  45. data/lib/graphql/pagination/relation_connection.rb +2 -0
  46. data/lib/graphql/query/context.rb +155 -196
  47. data/lib/graphql/query/input_validation_result.rb +1 -1
  48. data/lib/graphql/query/null_context.rb +0 -3
  49. data/lib/graphql/query/validation_pipeline.rb +10 -34
  50. data/lib/graphql/query/variables.rb +7 -20
  51. data/lib/graphql/query.rb +32 -42
  52. data/lib/graphql/railtie.rb +0 -104
  53. data/lib/graphql/rake_task/validate.rb +1 -1
  54. data/lib/graphql/rake_task.rb +29 -1
  55. data/lib/graphql/relay/range_add.rb +9 -20
  56. data/lib/graphql/relay.rb +0 -15
  57. data/lib/graphql/schema/addition.rb +7 -9
  58. data/lib/graphql/schema/argument.rb +36 -43
  59. data/lib/graphql/schema/build_from_definition.rb +32 -18
  60. data/lib/graphql/schema/directive/one_of.rb +12 -0
  61. data/lib/graphql/schema/directive/transform.rb +1 -1
  62. data/lib/graphql/schema/directive.rb +12 -23
  63. data/lib/graphql/schema/enum.rb +28 -39
  64. data/lib/graphql/schema/enum_value.rb +5 -25
  65. data/lib/graphql/schema/field/connection_extension.rb +4 -0
  66. data/lib/graphql/schema/field.rb +237 -339
  67. data/lib/graphql/schema/input_object.rb +56 -67
  68. data/lib/graphql/schema/interface.rb +0 -35
  69. data/lib/graphql/schema/introspection_system.rb +3 -8
  70. data/lib/graphql/schema/late_bound_type.rb +8 -2
  71. data/lib/graphql/schema/list.rb +0 -6
  72. data/lib/graphql/schema/loader.rb +1 -2
  73. data/lib/graphql/schema/member/base_dsl_methods.rb +17 -19
  74. data/lib/graphql/schema/member/build_type.rb +5 -7
  75. data/lib/graphql/schema/member/has_arguments.rb +146 -55
  76. data/lib/graphql/schema/member/has_ast_node.rb +12 -0
  77. data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
  78. data/lib/graphql/schema/member/has_directives.rb +81 -59
  79. data/lib/graphql/schema/member/has_fields.rb +17 -4
  80. data/lib/graphql/schema/member/has_interfaces.rb +49 -10
  81. data/lib/graphql/schema/member/has_validators.rb +31 -5
  82. data/lib/graphql/schema/member/relay_shortcuts.rb +47 -2
  83. data/lib/graphql/schema/member/type_system_helpers.rb +17 -0
  84. data/lib/graphql/schema/member/validates_input.rb +1 -1
  85. data/lib/graphql/schema/member.rb +0 -6
  86. data/lib/graphql/schema/mutation.rb +0 -9
  87. data/lib/graphql/schema/non_null.rb +1 -7
  88. data/lib/graphql/schema/object.rb +15 -52
  89. data/lib/graphql/schema/relay_classic_mutation.rb +53 -42
  90. data/lib/graphql/schema/resolver/has_payload_type.rb +20 -10
  91. data/lib/graphql/schema/resolver.rb +41 -42
  92. data/lib/graphql/schema/scalar.rb +7 -22
  93. data/lib/graphql/schema/subscription.rb +0 -7
  94. data/lib/graphql/schema/timeout.rb +24 -28
  95. data/lib/graphql/schema/type_membership.rb +3 -0
  96. data/lib/graphql/schema/union.rb +10 -17
  97. data/lib/graphql/schema/warden.rb +34 -8
  98. data/lib/graphql/schema/wrapper.rb +0 -5
  99. data/lib/graphql/schema.rb +241 -973
  100. data/lib/graphql/static_validation/all_rules.rb +1 -0
  101. data/lib/graphql/static_validation/base_visitor.rb +4 -21
  102. data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
  103. data/lib/graphql/static_validation/error.rb +2 -2
  104. data/lib/graphql/static_validation/literal_validator.rb +19 -1
  105. data/lib/graphql/static_validation/rules/directives_are_defined.rb +11 -5
  106. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
  107. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
  108. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
  109. data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +12 -6
  110. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
  111. data/lib/graphql/static_validation/validator.rb +3 -25
  112. data/lib/graphql/static_validation.rb +0 -2
  113. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -1
  114. data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
  115. data/lib/graphql/subscriptions/event.rb +3 -8
  116. data/lib/graphql/subscriptions/instrumentation.rb +0 -51
  117. data/lib/graphql/subscriptions.rb +32 -20
  118. data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
  119. data/lib/graphql/tracing/appoptics_trace.rb +231 -0
  120. data/lib/graphql/tracing/appsignal_trace.rb +71 -0
  121. data/lib/graphql/tracing/data_dog_trace.rb +148 -0
  122. data/lib/graphql/tracing/data_dog_tracing.rb +2 -0
  123. data/lib/graphql/tracing/new_relic_trace.rb +75 -0
  124. data/lib/graphql/tracing/notifications_trace.rb +41 -0
  125. data/lib/graphql/tracing/platform_trace.rb +107 -0
  126. data/lib/graphql/tracing/platform_tracing.rb +26 -40
  127. data/lib/graphql/tracing/prometheus_trace.rb +89 -0
  128. data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
  129. data/lib/graphql/tracing/scout_trace.rb +72 -0
  130. data/lib/graphql/tracing/statsd_trace.rb +56 -0
  131. data/lib/graphql/tracing.rb +136 -40
  132. data/lib/graphql/type_kinds.rb +6 -3
  133. data/lib/graphql/types/iso_8601_date.rb +4 -1
  134. data/lib/graphql/types/iso_8601_date_time.rb +4 -0
  135. data/lib/graphql/types/relay/base_connection.rb +16 -6
  136. data/lib/graphql/types/relay/connection_behaviors.rb +29 -27
  137. data/lib/graphql/types/relay/edge_behaviors.rb +16 -5
  138. data/lib/graphql/types/relay/node_behaviors.rb +12 -2
  139. data/lib/graphql/types/relay/page_info_behaviors.rb +7 -2
  140. data/lib/graphql/types/relay.rb +0 -3
  141. data/lib/graphql/types/string.rb +1 -1
  142. data/lib/graphql/version.rb +1 -1
  143. data/lib/graphql.rb +13 -74
  144. metadata +30 -133
  145. data/lib/graphql/analysis/analyze_query.rb +0 -98
  146. data/lib/graphql/analysis/field_usage.rb +0 -45
  147. data/lib/graphql/analysis/max_query_complexity.rb +0 -26
  148. data/lib/graphql/analysis/max_query_depth.rb +0 -26
  149. data/lib/graphql/analysis/query_complexity.rb +0 -88
  150. data/lib/graphql/analysis/query_depth.rb +0 -43
  151. data/lib/graphql/analysis/reducer_state.rb +0 -48
  152. data/lib/graphql/argument.rb +0 -131
  153. data/lib/graphql/authorization.rb +0 -82
  154. data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
  155. data/lib/graphql/backwards_compatibility.rb +0 -61
  156. data/lib/graphql/base_type.rb +0 -232
  157. data/lib/graphql/boolean_type.rb +0 -2
  158. data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
  159. data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
  160. data/lib/graphql/compatibility/execution_specification.rb +0 -436
  161. data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
  162. data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
  163. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
  164. data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
  165. data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
  166. data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
  167. data/lib/graphql/compatibility.rb +0 -5
  168. data/lib/graphql/define/assign_argument.rb +0 -12
  169. data/lib/graphql/define/assign_connection.rb +0 -13
  170. data/lib/graphql/define/assign_enum_value.rb +0 -18
  171. data/lib/graphql/define/assign_global_id_field.rb +0 -11
  172. data/lib/graphql/define/assign_mutation_function.rb +0 -34
  173. data/lib/graphql/define/assign_object_field.rb +0 -42
  174. data/lib/graphql/define/defined_object_proxy.rb +0 -53
  175. data/lib/graphql/define/instance_definable.rb +0 -255
  176. data/lib/graphql/define/no_definition_error.rb +0 -7
  177. data/lib/graphql/define/non_null_with_bang.rb +0 -16
  178. data/lib/graphql/define/type_definer.rb +0 -31
  179. data/lib/graphql/define.rb +0 -31
  180. data/lib/graphql/deprecated_dsl.rb +0 -55
  181. data/lib/graphql/directive/deprecated_directive.rb +0 -2
  182. data/lib/graphql/directive/include_directive.rb +0 -2
  183. data/lib/graphql/directive/skip_directive.rb +0 -2
  184. data/lib/graphql/directive.rb +0 -107
  185. data/lib/graphql/enum_type.rb +0 -133
  186. data/lib/graphql/execution/execute.rb +0 -333
  187. data/lib/graphql/execution/flatten.rb +0 -40
  188. data/lib/graphql/execution/instrumentation.rb +0 -92
  189. data/lib/graphql/execution/lazy/resolve.rb +0 -91
  190. data/lib/graphql/execution/typecast.rb +0 -50
  191. data/lib/graphql/field/resolve.rb +0 -59
  192. data/lib/graphql/field.rb +0 -226
  193. data/lib/graphql/float_type.rb +0 -2
  194. data/lib/graphql/function.rb +0 -128
  195. data/lib/graphql/id_type.rb +0 -2
  196. data/lib/graphql/input_object_type.rb +0 -138
  197. data/lib/graphql/int_type.rb +0 -2
  198. data/lib/graphql/interface_type.rb +0 -72
  199. data/lib/graphql/internal_representation/document.rb +0 -27
  200. data/lib/graphql/internal_representation/node.rb +0 -206
  201. data/lib/graphql/internal_representation/print.rb +0 -51
  202. data/lib/graphql/internal_representation/rewrite.rb +0 -184
  203. data/lib/graphql/internal_representation/scope.rb +0 -88
  204. data/lib/graphql/internal_representation/visit.rb +0 -36
  205. data/lib/graphql/internal_representation.rb +0 -7
  206. data/lib/graphql/language/lexer.rl +0 -260
  207. data/lib/graphql/list_type.rb +0 -80
  208. data/lib/graphql/non_null_type.rb +0 -71
  209. data/lib/graphql/object_type.rb +0 -130
  210. data/lib/graphql/query/arguments.rb +0 -189
  211. data/lib/graphql/query/arguments_cache.rb +0 -24
  212. data/lib/graphql/query/executor.rb +0 -52
  213. data/lib/graphql/query/literal_input.rb +0 -136
  214. data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
  215. data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
  216. data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
  217. data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
  218. data/lib/graphql/query/serial_execution.rb +0 -40
  219. data/lib/graphql/relay/array_connection.rb +0 -83
  220. data/lib/graphql/relay/base_connection.rb +0 -189
  221. data/lib/graphql/relay/connection_instrumentation.rb +0 -54
  222. data/lib/graphql/relay/connection_resolve.rb +0 -43
  223. data/lib/graphql/relay/connection_type.rb +0 -54
  224. data/lib/graphql/relay/edge.rb +0 -27
  225. data/lib/graphql/relay/edge_type.rb +0 -19
  226. data/lib/graphql/relay/edges_instrumentation.rb +0 -39
  227. data/lib/graphql/relay/global_id_resolve.rb +0 -17
  228. data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
  229. data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
  230. data/lib/graphql/relay/mutation/resolve.rb +0 -56
  231. data/lib/graphql/relay/mutation/result.rb +0 -38
  232. data/lib/graphql/relay/mutation.rb +0 -106
  233. data/lib/graphql/relay/node.rb +0 -39
  234. data/lib/graphql/relay/page_info.rb +0 -7
  235. data/lib/graphql/relay/relation_connection.rb +0 -188
  236. data/lib/graphql/relay/type_extensions.rb +0 -32
  237. data/lib/graphql/scalar_type.rb +0 -91
  238. data/lib/graphql/schema/catchall_middleware.rb +0 -35
  239. data/lib/graphql/schema/default_parse_error.rb +0 -10
  240. data/lib/graphql/schema/default_type_error.rb +0 -17
  241. data/lib/graphql/schema/member/accepts_definition.rb +0 -164
  242. data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
  243. data/lib/graphql/schema/member/instrumentation.rb +0 -131
  244. data/lib/graphql/schema/middleware_chain.rb +0 -82
  245. data/lib/graphql/schema/possible_types.rb +0 -44
  246. data/lib/graphql/schema/rescue_middleware.rb +0 -60
  247. data/lib/graphql/schema/timeout_middleware.rb +0 -88
  248. data/lib/graphql/schema/traversal.rb +0 -228
  249. data/lib/graphql/schema/validation.rb +0 -313
  250. data/lib/graphql/static_validation/default_visitor.rb +0 -15
  251. data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
  252. data/lib/graphql/string_type.rb +0 -2
  253. data/lib/graphql/subscriptions/subscription_root.rb +0 -76
  254. data/lib/graphql/tracing/skylight_tracing.rb +0 -70
  255. data/lib/graphql/types/relay/default_relay.rb +0 -31
  256. data/lib/graphql/types/relay/node_field.rb +0 -24
  257. data/lib/graphql/types/relay/nodes_field.rb +0 -43
  258. data/lib/graphql/union_type.rb +0 -115
  259. data/lib/graphql/upgrader/member.rb +0 -937
  260. data/lib/graphql/upgrader/schema.rb +0 -38
@@ -162,7 +162,7 @@ rule
162
162
  | schema_keyword
163
163
 
164
164
  enum_value_definition:
165
- description_opt enum_name directives_list_opt { result = make_node(:EnumValueDefinition, name: val[1], directives: val[2], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1]) }
165
+ description_opt enum_name directives_list_opt { result = make_node(:EnumValueDefinition, name: val[1], directives: val[2], description: val[0] || get_description(val[1]), definition_line: val[1][1], position_source: val[0] || val[1]) }
166
166
 
167
167
  enum_value_definitions:
168
168
  enum_value_definition { result = [val[0]] }
@@ -180,9 +180,9 @@ rule
180
180
  name COLON input_value { result = make_node(:Argument, name: val[0], value: val[2], position_source: val[0])}
181
181
 
182
182
  literal_value:
183
- FLOAT { result = val[0].to_f }
184
- | INT { result = val[0].to_i }
185
- | STRING { result = val[0].to_s }
183
+ FLOAT { result = val[0][3].to_f }
184
+ | INT { result = val[0][3].to_i }
185
+ | STRING { result = val[0][3] }
186
186
  | TRUE { result = true }
187
187
  | FALSE { result = false }
188
188
  | null_value
@@ -284,14 +284,14 @@ rule
284
284
  | directive_definition
285
285
 
286
286
  schema_definition:
287
- SCHEMA directives_list_opt LCURLY operation_type_definition_list RCURLY { result = make_node(:SchemaDefinition, position_source: val[0], definition_line: val[0].line, directives: val[1], **val[3]) }
287
+ SCHEMA directives_list_opt LCURLY operation_type_definition_list RCURLY { result = make_node(:SchemaDefinition, position_source: val[0], definition_line: val[0][1], directives: val[1], **val[3]) }
288
288
 
289
289
  operation_type_definition_list:
290
290
  operation_type_definition
291
291
  | operation_type_definition_list operation_type_definition { result = val[0].merge(val[1]) }
292
292
 
293
293
  operation_type_definition:
294
- operation_type COLON name { result = { val[0].to_s.to_sym => val[2] } }
294
+ operation_type COLON name { result = { val[0][3].to_sym => val[2] } }
295
295
 
296
296
  type_definition:
297
297
  scalar_type_definition
@@ -321,13 +321,13 @@ rule
321
321
 
322
322
  object_type_extension:
323
323
  /* TODO - This first one shouldn't be necessary but parser is getting confused */
324
- EXTEND TYPE name implements LCURLY field_definition_list RCURLY { result = make_node(:ObjectTypeExtension, name: val[2], interfaces: val[3], directives: [], fields: val[5], position_source: val[0]) }
325
- | EXTEND TYPE name implements_opt directives_list_opt LCURLY field_definition_list RCURLY { result = make_node(:ObjectTypeExtension, name: val[2], interfaces: val[3], directives: val[4], fields: val[6], position_source: val[0]) }
324
+ EXTEND TYPE name implements field_definition_list_opt { result = make_node(:ObjectTypeExtension, name: val[2], interfaces: val[3], directives: [], fields: val[4], position_source: val[0]) }
325
+ | EXTEND TYPE name implements_opt directives_list_opt field_definition_list_opt { result = make_node(:ObjectTypeExtension, name: val[2], interfaces: val[3], directives: val[4], fields: val[5], position_source: val[0]) }
326
326
  | EXTEND TYPE name implements_opt directives_list { result = make_node(:ObjectTypeExtension, name: val[2], interfaces: val[3], directives: val[4], fields: [], position_source: val[0]) }
327
327
  | EXTEND TYPE name implements { result = make_node(:ObjectTypeExtension, name: val[2], interfaces: val[3], directives: [], fields: [], position_source: val[0]) }
328
328
 
329
329
  interface_type_extension:
330
- EXTEND INTERFACE name implements_opt directives_list_opt LCURLY field_definition_list RCURLY { result = make_node(:InterfaceTypeExtension, name: val[2], interfaces: val[3], directives: val[4], fields: val[6], position_source: val[0]) }
330
+ EXTEND INTERFACE name implements_opt directives_list_opt field_definition_list_opt { result = make_node(:InterfaceTypeExtension, name: val[2], interfaces: val[3], directives: val[4], fields: val[5], position_source: val[0]) }
331
331
  | EXTEND INTERFACE name implements_opt directives_list { result = make_node(:InterfaceTypeExtension, name: val[2], interfaces: val[3], directives: val[4], fields: [], position_source: val[0]) }
332
332
  | EXTEND INTERFACE name implements { result = make_node(:InterfaceTypeExtension, name: val[2], interfaces: val[3], directives: [], fields: [], position_source: val[0]) }
333
333
 
@@ -351,12 +351,12 @@ rule
351
351
 
352
352
  scalar_type_definition:
353
353
  description_opt SCALAR name directives_list_opt {
354
- result = make_node(:ScalarTypeDefinition, name: val[2], directives: val[3], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
354
+ result = make_node(:ScalarTypeDefinition, name: val[2], directives: val[3], description: val[0] || get_description(val[1]), definition_line: val[1][1], position_source: val[0] || val[1])
355
355
  }
356
356
 
357
357
  object_type_definition:
358
- description_opt TYPE name implements_opt directives_list_opt LCURLY field_definition_list RCURLY {
359
- result = make_node(:ObjectTypeDefinition, name: val[2], interfaces: val[3], directives: val[4], fields: val[6], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
358
+ description_opt TYPE name implements_opt directives_list_opt field_definition_list_opt {
359
+ result = make_node(:ObjectTypeDefinition, name: val[2], interfaces: val[3], directives: val[4], fields: val[5], description: val[0] || get_description(val[1]), definition_line: val[1][1], position_source: val[0] || val[1])
360
360
  }
361
361
 
362
362
  implements_opt:
@@ -378,7 +378,7 @@ rule
378
378
 
379
379
  input_value_definition:
380
380
  description_opt name COLON type default_value_opt directives_list_opt {
381
- result = make_node(:InputValueDefinition, name: val[1], type: val[3], default_value: val[4], directives: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
381
+ result = make_node(:InputValueDefinition, name: val[1], type: val[3], default_value: val[4], directives: val[5], description: val[0] || get_description(val[1]), definition_line: val[1][1], position_source: val[0] || val[1])
382
382
  }
383
383
 
384
384
  input_value_definition_list:
@@ -391,17 +391,21 @@ rule
391
391
 
392
392
  field_definition:
393
393
  description_opt name arguments_definitions_opt COLON type directives_list_opt {
394
- result = make_node(:FieldDefinition, name: val[1], arguments: val[2], type: val[4], directives: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
394
+ result = make_node(:FieldDefinition, name: val[1], arguments: val[2], type: val[4], directives: val[5], description: val[0] || get_description(val[1]), definition_line: val[1][1], position_source: val[0] || val[1])
395
395
  }
396
396
 
397
- field_definition_list:
397
+ field_definition_list_opt:
398
398
  /* none */ { result = EMPTY_ARRAY }
399
+ | LCURLY field_definition_list RCURLY { result = val[1] }
400
+
401
+ field_definition_list:
402
+ /* none - this is not actually valid but graphql-ruby used to print this */ { result = EMPTY_ARRAY }
399
403
  | field_definition { result = [val[0]] }
400
404
  | field_definition_list field_definition { val[0] << val[1] }
401
405
 
402
406
  interface_type_definition:
403
- description_opt INTERFACE name implements_opt directives_list_opt LCURLY field_definition_list RCURLY {
404
- result = make_node(:InterfaceTypeDefinition, name: val[2], interfaces: val[3], directives: val[4], fields: val[6], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
407
+ description_opt INTERFACE name implements_opt directives_list_opt field_definition_list_opt {
408
+ result = make_node(:InterfaceTypeDefinition, name: val[2], interfaces: val[3], directives: val[4], fields: val[5], description: val[0] || get_description(val[1]), definition_line: val[1][1], position_source: val[0] || val[1])
405
409
  }
406
410
 
407
411
  union_members:
@@ -410,22 +414,22 @@ rule
410
414
 
411
415
  union_type_definition:
412
416
  description_opt UNION name directives_list_opt EQUALS union_members {
413
- result = make_node(:UnionTypeDefinition, name: val[2], directives: val[3], types: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
417
+ result = make_node(:UnionTypeDefinition, name: val[2], directives: val[3], types: val[5], description: val[0] || get_description(val[1]), definition_line: val[1][1], position_source: val[0] || val[1])
414
418
  }
415
419
 
416
420
  enum_type_definition:
417
421
  description_opt ENUM name directives_list_opt LCURLY enum_value_definitions RCURLY {
418
- result = make_node(:EnumTypeDefinition, name: val[2], directives: val[3], values: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
422
+ result = make_node(:EnumTypeDefinition, name: val[2], directives: val[3], values: val[5], description: val[0] || get_description(val[1]), definition_line: val[1][1], position_source: val[0] || val[1])
419
423
  }
420
424
 
421
425
  input_object_type_definition:
422
426
  description_opt INPUT name directives_list_opt LCURLY input_value_definition_list RCURLY {
423
- result = make_node(:InputObjectTypeDefinition, name: val[2], directives: val[3], fields: val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
427
+ result = make_node(:InputObjectTypeDefinition, name: val[2], directives: val[3], fields: val[5], description: val[0] || get_description(val[1]), definition_line: val[1][1], position_source: val[0] || val[1])
424
428
  }
425
429
 
426
430
  directive_definition:
427
431
  description_opt DIRECTIVE DIR_SIGN name arguments_definitions_opt directive_repeatable_opt ON directive_locations {
428
- result = make_node(:DirectiveDefinition, name: val[3], arguments: val[4], locations: val[7], repeatable: !!val[5], description: val[0] || get_description(val[1]), definition_line: val[1].line, position_source: val[0] || val[1])
432
+ result = make_node(:DirectiveDefinition, name: val[3], arguments: val[4], locations: val[7], repeatable: !!val[5], description: val[0] || get_description(val[1]), definition_line: val[1][1], position_source: val[0] || val[1])
429
433
  }
430
434
 
431
435
  directive_repeatable_opt:
@@ -433,8 +437,8 @@ rule
433
437
  | REPEATABLE
434
438
 
435
439
  directive_locations:
436
- name { result = [make_node(:DirectiveLocation, name: val[0].to_s, position_source: val[0])] }
437
- | directive_locations PIPE name { val[0] << make_node(:DirectiveLocation, name: val[2].to_s, position_source: val[2]) }
440
+ name { result = [make_node(:DirectiveLocation, name: val[0][3], position_source: val[0])] }
441
+ | directive_locations PIPE name { val[0] << make_node(:DirectiveLocation, name: val[2][3], position_source: val[2]) }
438
442
  end
439
443
 
440
444
  ---- header ----
@@ -444,22 +448,22 @@ end
444
448
 
445
449
  EMPTY_ARRAY = [].freeze
446
450
 
447
- def initialize(query_string, filename:, tracer: Tracing::NullTracer)
451
+ def initialize(query_string, filename:, trace: Tracing::NullTrace)
448
452
  raise GraphQL::ParseError.new("No query string was present", nil, nil, query_string) if query_string.nil?
449
453
  @query_string = query_string
450
454
  @filename = filename
451
- @tracer = tracer
455
+ @trace = trace
452
456
  @reused_next_token = [nil, nil]
453
457
  end
454
458
 
455
459
  def parse_document
456
460
  @document ||= begin
457
461
  # Break the string into tokens
458
- @tracer.trace("lex", {query_string: @query_string}) do
459
- @tokens ||= GraphQL.scan(@query_string)
462
+ @trace.lex(query_string: @query_string) do
463
+ @tokens ||= GraphQL::Language::Lexer.tokenize(@query_string)
460
464
  end
461
465
  # From the tokens, build an AST
462
- @tracer.trace("parse", {query_string: @query_string}) do
466
+ @trace.parse(query_string: @query_string) do
463
467
  if @tokens.empty?
464
468
  raise GraphQL::ParseError.new("Unexpected end of document", nil, nil, @query_string)
465
469
  else
@@ -472,17 +476,17 @@ end
472
476
  class << self
473
477
  attr_accessor :cache
474
478
 
475
- def parse(query_string, filename: nil, tracer: GraphQL::Tracing::NullTracer)
476
- new(query_string, filename: filename, tracer: tracer).parse_document
479
+ def parse(query_string, filename: nil, trace: GraphQL::Tracing::NullTrace)
480
+ new(query_string, filename: filename, trace: trace).parse_document
477
481
  end
478
482
 
479
- def parse_file(filename, tracer: GraphQL::Tracing::NullTracer)
483
+ def parse_file(filename, trace: GraphQL::Tracing::NullTrace)
480
484
  if cache
481
485
  cache.fetch(filename) do
482
- parse(File.read(filename), filename: filename, tracer: tracer)
486
+ parse(File.read(filename), filename: filename, trace: trace)
483
487
  end
484
488
  else
485
- parse(File.read(filename), filename: filename, tracer: tracer)
489
+ parse(File.read(filename), filename: filename, trace: trace)
486
490
  end
487
491
  end
488
492
  end
@@ -494,7 +498,7 @@ def next_token
494
498
  if lexer_token.nil?
495
499
  nil
496
500
  else
497
- @reused_next_token[0] = lexer_token.name
501
+ @reused_next_token[0] = lexer_token[0]
498
502
  @reused_next_token[1] = lexer_token
499
503
  @reused_next_token
500
504
  end
@@ -505,13 +509,13 @@ def get_description(token)
505
509
 
506
510
  loop do
507
511
  prev_token = token
508
- token = token.prev_token
512
+ token = token[4]
509
513
 
510
514
  break if token.nil?
511
- break if token.name != :COMMENT
512
- break if prev_token.line != token.line + 1
515
+ break if token[0] != :COMMENT
516
+ break if prev_token[1] != token[1] + 1
513
517
 
514
- comments.unshift(token.to_s.sub(/^#\s*/, ""))
518
+ comments.unshift(token[3].sub(/^#\s*/, ""))
515
519
  end
516
520
 
517
521
  return nil if comments.empty?
@@ -527,11 +531,12 @@ def on_error(parser_token_id, lexer_token, vstack)
527
531
  if parser_token_name.nil?
528
532
  raise GraphQL::ParseError.new("Parse Error on unknown token: {token_id: #{parser_token_id}, lexer_token: #{lexer_token}} from #{@query_string}", nil, nil, @query_string, filename: @filename)
529
533
  else
530
- line, col = lexer_token.line_and_column
531
- if lexer_token.name == :BAD_UNICODE_ESCAPE
532
- raise GraphQL::ParseError.new("Parse error on bad Unicode escape sequence: #{lexer_token.to_s.inspect} (#{parser_token_name}) at [#{line}, #{col}]", line, col, @query_string, filename: @filename)
534
+ line = lexer_token[1]
535
+ col = lexer_token[2]
536
+ if lexer_token[0] == :BAD_UNICODE_ESCAPE
537
+ raise GraphQL::ParseError.new("Parse error on bad Unicode escape sequence: #{lexer_token[3].inspect} (#{parser_token_name}) at [#{line}, #{col}]", line, col, @query_string, filename: @filename)
533
538
  else
534
- raise GraphQL::ParseError.new("Parse error on #{lexer_token.to_s.inspect} (#{parser_token_name}) at [#{line}, #{col}]", line, col, @query_string, filename: @filename)
539
+ raise GraphQL::ParseError.new("Parse error on #{lexer_token[3].inspect} (#{parser_token_name}) at [#{line}, #{col}]", line, col, @query_string, filename: @filename)
535
540
  end
536
541
  end
537
542
  end
@@ -539,8 +544,8 @@ end
539
544
 
540
545
  def make_node(node_name, assigns)
541
546
  assigns.each do |key, value|
542
- if key != :position_source && value.is_a?(GraphQL::Language::Token)
543
- assigns[key] = value.to_s
547
+ if key != :position_source && value.is_a?(Array) && value[0].is_a?(Symbol)
548
+ assigns[key] = value[3]
544
549
  end
545
550
  end
546
551
 
@@ -132,10 +132,11 @@ module GraphQL
132
132
  end
133
133
 
134
134
  def print_schema_definition(schema)
135
- if (schema.query.nil? || schema.query == 'Query') &&
136
- (schema.mutation.nil? || schema.mutation == 'Mutation') &&
137
- (schema.subscription.nil? || schema.subscription == 'Subscription') &&
138
- (schema.directives.empty?)
135
+ has_conventional_names = (schema.query.nil? || schema.query == 'Query') &&
136
+ (schema.mutation.nil? || schema.mutation == 'Mutation') &&
137
+ (schema.subscription.nil? || schema.subscription == 'Subscription')
138
+
139
+ if has_conventional_names && schema.directives.empty?
139
140
  return
140
141
  end
141
142
 
@@ -145,14 +146,22 @@ module GraphQL
145
146
  out << "\n "
146
147
  out << print_node(dir)
147
148
  end
148
- out << "\n{"
149
- else
150
- out << " {\n"
149
+ if !has_conventional_names
150
+ out << "\n"
151
+ end
151
152
  end
152
- out << " query: #{schema.query}\n" if schema.query
153
- out << " mutation: #{schema.mutation}\n" if schema.mutation
154
- out << " subscription: #{schema.subscription}\n" if schema.subscription
155
- out << "}"
153
+
154
+ if !has_conventional_names
155
+ if schema.directives.empty?
156
+ out << " "
157
+ end
158
+ out << "{\n"
159
+ out << " query: #{schema.query}\n" if schema.query
160
+ out << " mutation: #{schema.mutation}\n" if schema.mutation
161
+ out << " subscription: #{schema.subscription}\n" if schema.subscription
162
+ out << "}"
163
+ end
164
+ out
156
165
  end
157
166
 
158
167
  def print_scalar_type_definition(scalar_type)
@@ -236,12 +245,15 @@ module GraphQL
236
245
  out = print_description(input_object_type)
237
246
  out << "input #{input_object_type.name}"
238
247
  out << print_directives(input_object_type.directives)
239
- out << " {\n"
240
- input_object_type.fields.each.with_index do |field, i|
241
- out << print_description(field, indent: ' ', first_in_block: i == 0)
242
- out << " #{print_input_value_definition(field)}\n"
248
+ if !input_object_type.fields.empty?
249
+ out << " {\n"
250
+ input_object_type.fields.each.with_index do |field, i|
251
+ out << print_description(field, indent: ' ', first_in_block: i == 0)
252
+ out << " #{print_input_value_definition(field)}\n"
253
+ end
254
+ out << "}"
243
255
  end
244
- out << "}"
256
+ out
245
257
  end
246
258
 
247
259
  def print_directive_definition(directive)
@@ -267,12 +279,16 @@ module GraphQL
267
279
  end
268
280
 
269
281
  def print_field_definitions(fields)
270
- out = " {\n".dup
271
- fields.each.with_index do |field, i|
272
- out << print_description(field, indent: ' ', first_in_block: i == 0)
273
- out << " #{print_field_definition(field)}\n"
282
+ if fields.empty?
283
+ ""
284
+ else
285
+ out = " {\n".dup
286
+ fields.each.with_index do |field, i|
287
+ out << print_description(field, indent: ' ', first_in_block: i == 0)
288
+ out << " #{print_field_definition(field)}\n"
289
+ end
290
+ out << "}"
274
291
  end
275
- out << "}"
276
292
  end
277
293
 
278
294
  def print_directives(directives)
@@ -65,7 +65,9 @@ module GraphQL
65
65
  # Visit `document` and all children, applying hooks as you go
66
66
  # @return [void]
67
67
  def visit
68
- result = on_node_with_modifications(@document, nil)
68
+ # `@document` may be any kind of node:
69
+ visit_method = :"#{@document.visit_method}_with_modifications"
70
+ result = public_send(visit_method, @document, nil)
69
71
  @result = if result.is_a?(Array)
70
72
  result.first
71
73
  else
@@ -74,104 +76,210 @@ module GraphQL
74
76
  end
75
77
  end
76
78
 
77
- # Call the user-defined handler for `node`.
78
- def visit_node(node, parent)
79
- public_send(node.visit_method, node, parent)
80
- end
79
+ # We don't use `alias` here because it breaks `super`
80
+ def self.make_visit_methods(ast_node_class)
81
+ node_method = ast_node_class.visit_method
82
+ children_of_type = ast_node_class.children_of_type
83
+ child_visit_method = :"#{node_method}_children"
81
84
 
82
- # The default implementation for visiting an AST node.
83
- # It doesn't _do_ anything, but it continues to visiting the node's children.
84
- # To customize this hook, override one of its make_visit_methodes (or the base method?)
85
- # in your subclasses.
86
- #
87
- # For compatibility, it calls hook procs, too.
88
- # @param node [GraphQL::Language::Nodes::AbstractNode] the node being visited
89
- # @param parent [GraphQL::Language::Nodes::AbstractNode, nil] the previously-visited node, or `nil` if this is the root node.
90
- # @return [Array, nil] If there were modifications, it returns an array of new nodes, otherwise, it returns `nil`.
91
- def on_abstract_node(node, parent)
92
- if node.equal?(DELETE_NODE)
93
- # This might be passed to `super(DELETE_NODE, ...)`
94
- # by a user hook, don't want to keep visiting in that case.
95
- nil
96
- else
97
- # Run hooks if there are any
98
- new_node = node
99
- no_hooks = !@visitors.key?(node.class)
100
- if no_hooks || begin_visit(new_node, parent)
101
- node.children.each do |child_node|
102
- new_child_and_node = on_node_with_modifications(child_node, new_node)
103
- # Reassign `node` in case the child hook makes a modification
104
- if new_child_and_node.is_a?(Array)
105
- new_node = new_child_and_node[1]
85
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
86
+ # The default implementation for visiting an AST node.
87
+ # It doesn't _do_ anything, but it continues to visiting the node's children.
88
+ # To customize this hook, override one of its make_visit_methods (or the base method?)
89
+ # in your subclasses.
90
+ #
91
+ # For compatibility, it calls hook procs, too.
92
+ # @param node [GraphQL::Language::Nodes::AbstractNode] the node being visited
93
+ # @param parent [GraphQL::Language::Nodes::AbstractNode, nil] the previously-visited node, or `nil` if this is the root node.
94
+ # @return [Array, nil] If there were modifications, it returns an array of new nodes, otherwise, it returns `nil`.
95
+ def #{node_method}(node, parent)
96
+ if node.equal?(DELETE_NODE)
97
+ # This might be passed to `super(DELETE_NODE, ...)`
98
+ # by a user hook, don't want to keep visiting in that case.
99
+ [node, parent]
100
+ else
101
+ # Run hooks if there are any
102
+ new_node = node
103
+ no_hooks = !@visitors.key?(node.class)
104
+ if no_hooks || begin_visit(new_node, parent)
105
+ #{
106
+ if method_defined?(child_visit_method)
107
+ "new_node = #{child_visit_method}(new_node)"
108
+ elsif children_of_type
109
+ children_of_type.map do |child_accessor, child_class|
110
+ "node.#{child_accessor}.each do |child_node|
111
+ new_child_and_node = #{child_class.visit_method}_with_modifications(child_node, new_node)
112
+ # Reassign `node` in case the child hook makes a modification
113
+ if new_child_and_node.is_a?(Array)
114
+ new_node = new_child_and_node[1]
115
+ end
116
+ end"
117
+ end.join("\n")
118
+ else
119
+ ""
120
+ end
121
+ }
122
+ end
123
+ end_visit(new_node, parent) unless no_hooks
124
+
125
+ if new_node.equal?(node)
126
+ [node, parent]
127
+ else
128
+ [new_node, parent]
106
129
  end
107
130
  end
108
131
  end
109
- end_visit(new_node, parent) unless no_hooks
110
132
 
111
- if new_node.equal?(node)
112
- nil
133
+ def #{node_method}_with_modifications(node, parent)
134
+ new_node_and_new_parent = #{node_method}(node, parent)
135
+ apply_modifications(node, parent, new_node_and_new_parent)
136
+ end
137
+ RUBY
138
+ end
139
+
140
+ def on_document_children(document_node)
141
+ new_node = document_node
142
+ document_node.children.each do |child_node|
143
+ visit_method = :"#{child_node.visit_method}_with_modifications"
144
+ new_child_and_node = public_send(visit_method, child_node, new_node)
145
+ # Reassign `node` in case the child hook makes a modification
146
+ if new_child_and_node.is_a?(Array)
147
+ new_node = new_child_and_node[1]
148
+ end
149
+ end
150
+ new_node
151
+ end
152
+
153
+ def on_field_children(new_node)
154
+ new_node.arguments.each do |arg_node| # rubocop:disable Development/ContextIsPassedCop
155
+ new_child_and_node = on_argument_with_modifications(arg_node, new_node)
156
+ # Reassign `node` in case the child hook makes a modification
157
+ if new_child_and_node.is_a?(Array)
158
+ new_node = new_child_and_node[1]
159
+ end
160
+ end
161
+ new_node = visit_directives(new_node)
162
+ new_node = visit_selections(new_node)
163
+ new_node
164
+ end
165
+
166
+ def visit_directives(new_node)
167
+ new_node.directives.each do |dir_node|
168
+ new_child_and_node = on_directive_with_modifications(dir_node, new_node)
169
+ # Reassign `node` in case the child hook makes a modification
170
+ if new_child_and_node.is_a?(Array)
171
+ new_node = new_child_and_node[1]
172
+ end
173
+ end
174
+ new_node
175
+ end
176
+
177
+ def visit_selections(new_node)
178
+ new_node.selections.each do |selection|
179
+ new_child_and_node = case selection
180
+ when GraphQL::Language::Nodes::Field
181
+ on_field_with_modifications(selection, new_node)
182
+ when GraphQL::Language::Nodes::InlineFragment
183
+ on_inline_fragment_with_modifications(selection, new_node)
184
+ when GraphQL::Language::Nodes::FragmentSpread
185
+ on_fragment_spread_with_modifications(selection, new_node)
113
186
  else
114
- [new_node, parent]
187
+ raise ArgumentError, "Invariant: unexpected field selection #{selection.class} (#{selection.inspect})"
188
+ end
189
+ # Reassign `node` in case the child hook makes a modification
190
+ if new_child_and_node.is_a?(Array)
191
+ new_node = new_child_and_node[1]
115
192
  end
116
193
  end
194
+ new_node
117
195
  end
118
196
 
119
- # We don't use `alias` here because it breaks `super`
120
- def self.make_visit_method(node_method)
121
- class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
122
- def #{node_method}(node, parent)
123
- child_mod = on_abstract_node(node, parent)
124
- # If visiting the children returned changes, continue passing those.
125
- child_mod || [node, parent]
197
+ def on_fragment_definition_children(new_node)
198
+ new_node = visit_directives(new_node)
199
+ new_node = visit_selections(new_node)
200
+ new_node
201
+ end
202
+
203
+ alias :on_inline_fragment_children :on_fragment_definition_children
204
+
205
+ def on_operation_definition_children(new_node)
206
+ new_node.variables.each do |arg_node|
207
+ new_child_and_node = on_variable_definition_with_modifications(arg_node, new_node)
208
+ # Reassign `node` in case the child hook makes a modification
209
+ if new_child_and_node.is_a?(Array)
210
+ new_node = new_child_and_node[1]
126
211
  end
127
- RUBY
212
+ end
213
+ new_node = visit_directives(new_node)
214
+ new_node = visit_selections(new_node)
215
+ new_node
216
+ end
217
+
218
+ def on_argument_children(new_node)
219
+ new_node.children.each do |value_node|
220
+ new_child_and_node = case value_node
221
+ when Language::Nodes::VariableIdentifier
222
+ on_variable_identifier_with_modifications(value_node, new_node)
223
+ when Language::Nodes::InputObject
224
+ on_input_object_with_modifications(value_node, new_node)
225
+ when Language::Nodes::Enum
226
+ on_enum_with_modifications(value_node, new_node)
227
+ when Language::Nodes::NullValue
228
+ on_null_value_with_modifications(value_node, new_node)
229
+ else
230
+ raise ArgumentError, "Invariant: unexpected argument value node #{value_node.class} (#{value_node.inspect})"
231
+ end
232
+ # Reassign `node` in case the child hook makes a modification
233
+ if new_child_and_node.is_a?(Array)
234
+ new_node = new_child_and_node[1]
235
+ end
236
+ end
237
+ new_node
128
238
  end
129
239
 
130
- make_visit_method :on_argument
131
- make_visit_method :on_directive
132
- make_visit_method :on_directive_definition
133
- make_visit_method :on_directive_location
134
- make_visit_method :on_document
135
- make_visit_method :on_enum
136
- make_visit_method :on_enum_type_definition
137
- make_visit_method :on_enum_type_extension
138
- make_visit_method :on_enum_value_definition
139
- make_visit_method :on_field
140
- make_visit_method :on_field_definition
141
- make_visit_method :on_fragment_definition
142
- make_visit_method :on_fragment_spread
143
- make_visit_method :on_inline_fragment
144
- make_visit_method :on_input_object
145
- make_visit_method :on_input_object_type_definition
146
- make_visit_method :on_input_object_type_extension
147
- make_visit_method :on_input_value_definition
148
- make_visit_method :on_interface_type_definition
149
- make_visit_method :on_interface_type_extension
150
- make_visit_method :on_list_type
151
- make_visit_method :on_non_null_type
152
- make_visit_method :on_null_value
153
- make_visit_method :on_object_type_definition
154
- make_visit_method :on_object_type_extension
155
- make_visit_method :on_operation_definition
156
- make_visit_method :on_scalar_type_definition
157
- make_visit_method :on_scalar_type_extension
158
- make_visit_method :on_schema_definition
159
- make_visit_method :on_schema_extension
160
- make_visit_method :on_type_name
161
- make_visit_method :on_union_type_definition
162
- make_visit_method :on_union_type_extension
163
- make_visit_method :on_variable_definition
164
- make_visit_method :on_variable_identifier
240
+ [
241
+ Language::Nodes::Argument,
242
+ Language::Nodes::Directive,
243
+ Language::Nodes::DirectiveDefinition,
244
+ Language::Nodes::DirectiveLocation,
245
+ Language::Nodes::Document,
246
+ Language::Nodes::Enum,
247
+ Language::Nodes::EnumTypeDefinition,
248
+ Language::Nodes::EnumTypeExtension,
249
+ Language::Nodes::EnumValueDefinition,
250
+ Language::Nodes::Field,
251
+ Language::Nodes::FieldDefinition,
252
+ Language::Nodes::FragmentDefinition,
253
+ Language::Nodes::FragmentSpread,
254
+ Language::Nodes::InlineFragment,
255
+ Language::Nodes::InputObject,
256
+ Language::Nodes::InputObjectTypeDefinition,
257
+ Language::Nodes::InputObjectTypeExtension,
258
+ Language::Nodes::InputValueDefinition,
259
+ Language::Nodes::InterfaceTypeDefinition,
260
+ Language::Nodes::InterfaceTypeExtension,
261
+ Language::Nodes::ListType,
262
+ Language::Nodes::NonNullType,
263
+ Language::Nodes::NullValue,
264
+ Language::Nodes::ObjectTypeDefinition,
265
+ Language::Nodes::ObjectTypeExtension,
266
+ Language::Nodes::OperationDefinition,
267
+ Language::Nodes::ScalarTypeDefinition,
268
+ Language::Nodes::ScalarTypeExtension,
269
+ Language::Nodes::SchemaDefinition,
270
+ Language::Nodes::SchemaExtension,
271
+ Language::Nodes::TypeName,
272
+ Language::Nodes::UnionTypeDefinition,
273
+ Language::Nodes::UnionTypeExtension,
274
+ Language::Nodes::VariableDefinition,
275
+ Language::Nodes::VariableIdentifier,
276
+ ].each do |ast_node_class|
277
+ make_visit_methods(ast_node_class)
278
+ end
165
279
 
166
280
  private
167
281
 
168
- # Run the hooks for `node`, and if the hooks return a copy of `node`,
169
- # copy `parent` so that it contains the copy of that node as a child,
170
- # then return the copies
171
- # If a non-array value is returned, consuming functions should ignore
172
- # said value
173
- def on_node_with_modifications(node, parent)
174
- new_node_and_new_parent = visit_node(node, parent)
282
+ def apply_modifications(node, parent, new_node_and_new_parent)
175
283
  if new_node_and_new_parent.is_a?(Array)
176
284
  new_node = new_node_and_new_parent[0]
177
285
  new_parent = new_node_and_new_parent[1]