graphql 1.9.21 → 1.10.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/core.rb +0 -1
  3. data/lib/generators/graphql/install_generator.rb +0 -1
  4. data/lib/generators/graphql/mutation_generator.rb +1 -1
  5. data/lib/generators/graphql/templates/base_field.erb +4 -0
  6. data/lib/generators/graphql/templates/graphql_controller.erb +0 -5
  7. data/lib/generators/graphql/templates/mutation.erb +1 -1
  8. data/lib/generators/graphql/templates/schema.erb +1 -1
  9. data/lib/graphql.rb +1 -11
  10. data/lib/graphql/analysis/ast.rb +2 -2
  11. data/lib/graphql/analysis/ast/analyzer.rb +4 -23
  12. data/lib/graphql/analysis/ast/max_query_complexity.rb +3 -3
  13. data/lib/graphql/analysis/ast/max_query_depth.rb +3 -7
  14. data/lib/graphql/analysis/ast/query_complexity.rb +2 -2
  15. data/lib/graphql/argument.rb +6 -2
  16. data/lib/graphql/backtrace/table.rb +10 -2
  17. data/lib/graphql/base_type.rb +5 -1
  18. data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +5 -9
  19. data/lib/graphql/define/assign_object_field.rb +2 -2
  20. data/lib/graphql/define/defined_object_proxy.rb +0 -3
  21. data/lib/graphql/define/instance_definable.rb +3 -14
  22. data/lib/graphql/enum_type.rb +4 -0
  23. data/lib/graphql/execution/directive_checks.rb +2 -2
  24. data/lib/graphql/execution/errors.rb +14 -15
  25. data/lib/graphql/execution/execute.rb +1 -1
  26. data/lib/graphql/execution/interpreter/runtime.rb +17 -39
  27. data/lib/graphql/execution/multiplex.rb +3 -3
  28. data/lib/graphql/field.rb +8 -0
  29. data/lib/graphql/filter.rb +1 -1
  30. data/lib/graphql/function.rb +1 -1
  31. data/lib/graphql/input_object_type.rb +1 -2
  32. data/lib/graphql/introspection/entry_points.rb +1 -2
  33. data/lib/graphql/introspection/input_value_type.rb +27 -9
  34. data/lib/graphql/introspection/schema_type.rb +1 -2
  35. data/lib/graphql/language/block_string.rb +2 -2
  36. data/lib/graphql/language/document_from_schema_definition.rb +5 -11
  37. data/lib/graphql/language/lexer.rb +48 -49
  38. data/lib/graphql/language/lexer.rl +48 -49
  39. data/lib/graphql/language/nodes.rb +11 -14
  40. data/lib/graphql/language/parser.rb +645 -650
  41. data/lib/graphql/language/parser.y +7 -8
  42. data/lib/graphql/language/token.rb +1 -1
  43. data/lib/graphql/non_null_type.rb +0 -10
  44. data/lib/graphql/pagination.rb +6 -0
  45. data/lib/graphql/pagination/active_record_relation_connection.rb +35 -0
  46. data/lib/graphql/pagination/array_connection.rb +78 -0
  47. data/lib/graphql/pagination/connection.rb +150 -0
  48. data/lib/graphql/pagination/connections.rb +103 -0
  49. data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
  50. data/lib/graphql/pagination/relation_connection.rb +157 -0
  51. data/lib/graphql/pagination/sequel_dataset_connection.rb +28 -0
  52. data/lib/graphql/query.rb +1 -7
  53. data/lib/graphql/query/arguments.rb +3 -9
  54. data/lib/graphql/query/context.rb +9 -31
  55. data/lib/graphql/query/literal_input.rb +29 -10
  56. data/lib/graphql/query/null_context.rb +0 -4
  57. data/lib/graphql/query/variable_validation_error.rb +1 -1
  58. data/lib/graphql/query/variables.rb +2 -4
  59. data/lib/graphql/relay/base_connection.rb +7 -3
  60. data/lib/graphql/relay/edges_instrumentation.rb +1 -1
  61. data/lib/graphql/relay/node.rb +2 -2
  62. data/lib/graphql/relay/relation_connection.rb +5 -9
  63. data/lib/graphql/schema.rb +27 -68
  64. data/lib/graphql/schema/argument.rb +31 -5
  65. data/lib/graphql/schema/base_64_bp.rb +2 -3
  66. data/lib/graphql/schema/build_from_definition.rb +113 -179
  67. data/lib/graphql/schema/build_from_definition/resolve_map.rb +10 -4
  68. data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +1 -1
  69. data/lib/graphql/schema/directive.rb +6 -7
  70. data/lib/graphql/schema/directive/feature.rb +1 -1
  71. data/lib/graphql/schema/enum.rb +1 -0
  72. data/lib/graphql/schema/enum_value.rb +4 -1
  73. data/lib/graphql/schema/field.rb +37 -39
  74. data/lib/graphql/schema/field/connection_extension.rb +11 -1
  75. data/lib/graphql/schema/input_object.rb +2 -5
  76. data/lib/graphql/schema/interface.rb +2 -0
  77. data/lib/graphql/schema/introspection_system.rb +1 -4
  78. data/lib/graphql/schema/loader.rb +6 -12
  79. data/lib/graphql/schema/member.rb +2 -0
  80. data/lib/graphql/schema/member/base_dsl_methods.rb +2 -2
  81. data/lib/graphql/schema/member/build_type.rb +4 -0
  82. data/lib/graphql/schema/member/cached_graphql_definition.rb +5 -0
  83. data/lib/graphql/schema/member/has_ast_node.rb +17 -0
  84. data/lib/graphql/schema/member/has_fields.rb +10 -16
  85. data/lib/graphql/schema/member/instrumentation.rb +1 -6
  86. data/lib/graphql/schema/member/type_system_helpers.rb +1 -1
  87. data/lib/graphql/schema/mutation.rb +1 -1
  88. data/lib/graphql/schema/object.rb +5 -6
  89. data/lib/graphql/schema/possible_types.rb +3 -3
  90. data/lib/graphql/schema/printer.rb +1 -3
  91. data/lib/graphql/schema/relay_classic_mutation.rb +2 -6
  92. data/lib/graphql/schema/resolver.rb +5 -35
  93. data/lib/graphql/schema/scalar.rb +1 -0
  94. data/lib/graphql/schema/subscription.rb +6 -6
  95. data/lib/graphql/schema/timeout_middleware.rb +2 -3
  96. data/lib/graphql/schema/type_expression.rb +27 -17
  97. data/lib/graphql/schema/union.rb +7 -26
  98. data/lib/graphql/schema/validation.rb +1 -17
  99. data/lib/graphql/schema/warden.rb +3 -77
  100. data/lib/graphql/schema/wrapper.rb +1 -1
  101. data/lib/graphql/static_validation/definition_dependencies.rb +12 -21
  102. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +9 -4
  103. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +10 -7
  104. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -1
  105. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +5 -5
  106. data/lib/graphql/static_validation/rules/fields_will_merge.rb +4 -4
  107. data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +3 -3
  108. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +3 -3
  109. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +5 -6
  110. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
  111. data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +1 -1
  112. data/lib/graphql/subscriptions.rb +7 -7
  113. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +2 -2
  114. data/lib/graphql/subscriptions/event.rb +5 -19
  115. data/lib/graphql/subscriptions/instrumentation.rb +9 -4
  116. data/lib/graphql/subscriptions/subscription_root.rb +2 -10
  117. data/lib/graphql/tracing/skylight_tracing.rb +0 -1
  118. data/lib/graphql/types/int.rb +1 -1
  119. data/lib/graphql/types/relay/base_connection.rb +3 -1
  120. data/lib/graphql/union_type.rb +23 -58
  121. data/lib/graphql/upgrader/member.rb +1 -1
  122. data/lib/graphql/version.rb +1 -1
  123. metadata +20 -13
  124. data/lib/generators/graphql/templates/base_mutation.erb +0 -8
  125. data/lib/graphql/schema/type_membership.rb +0 -34
@@ -20,7 +20,7 @@ module GraphQL
20
20
 
21
21
  def execute(ast_operation, root_type, query)
22
22
  result = resolve_root_selection(query)
23
- lazy_resolve_root_selection(result, **{query: query})
23
+ lazy_resolve_root_selection(result, {query: query})
24
24
  GraphQL::Execution::Flatten.call(query.context)
25
25
  end
26
26
 
@@ -11,7 +11,7 @@ module GraphQL
11
11
  # @return [GraphQL::Query]
12
12
  attr_reader :query
13
13
 
14
- # @return [Class<GraphQL::Schema>]
14
+ # @return [Class]
15
15
  attr_reader :schema
16
16
 
17
17
  # @return [GraphQL::Query::Context]
@@ -43,22 +43,19 @@ module GraphQL
43
43
  # might be stored up in lazies.
44
44
  # @return [void]
45
45
  def run_eager
46
-
47
46
  root_operation = query.selected_operation
48
47
  root_op_type = root_operation.operation_type || "query"
49
48
  legacy_root_type = schema.root_type_for_operation(root_op_type)
50
49
  root_type = legacy_root_type.metadata[:type_class] || raise("Invariant: type must be class-based: #{legacy_root_type}")
51
- path = []
52
- @interpreter_context[:current_object] = query.root_value
53
- @interpreter_context[:current_path] = path
54
50
  object_proxy = root_type.authorized_new(query.root_value, context)
55
51
  object_proxy = schema.sync_lazy(object_proxy)
56
52
  if object_proxy.nil?
57
53
  # Root .authorized? returned false.
58
- write_in_response(path, nil)
54
+ write_in_response([], nil)
59
55
  nil
60
56
  else
61
- evaluate_selections(path, context.scoped_context, object_proxy, root_type, root_operation.selections, root_operation_type: root_op_type)
57
+ path = []
58
+ evaluate_selections(path, object_proxy, root_type, root_operation.selections, root_operation_type: root_op_type)
62
59
  nil
63
60
  end
64
61
  end
@@ -118,9 +115,7 @@ module GraphQL
118
115
  end
119
116
  end
120
117
 
121
- def evaluate_selections(path, scoped_context, owner_object, owner_type, selections, root_operation_type: nil)
122
- @interpreter_context[:current_object] = owner_object
123
- @interpreter_context[:current_path] = path
118
+ def evaluate_selections(path, owner_object, owner_type, selections, root_operation_type: nil)
124
119
  selections_by_name = {}
125
120
  gather_selections(owner_object, owner_type, selections, selections_by_name)
126
121
  selections_by_name.each do |result_name, field_ast_nodes_or_ast_node|
@@ -163,7 +158,6 @@ module GraphQL
163
158
  @interpreter_context[:current_path] = next_path
164
159
  @interpreter_context[:current_field] = field_defn
165
160
 
166
- context.scoped_context = scoped_context
167
161
  object = owner_object
168
162
 
169
163
  if is_introspection
@@ -201,8 +195,6 @@ module GraphQL
201
195
  end
202
196
  end
203
197
 
204
- @interpreter_context[:current_arguments] = kwarg_arguments
205
-
206
198
  # Optimize for the case that field is selected only once
207
199
  if field_ast_nodes.nil? || field_ast_nodes.size == 1
208
200
  next_selections = ast_node.selections
@@ -214,15 +206,13 @@ module GraphQL
214
206
  field_result = resolve_with_directives(object, ast_node) do
215
207
  # Actually call the field resolver and capture the result
216
208
  app_result = begin
217
- query.with_error_handling do
218
- query.trace("execute_field", {owner: owner_type, field: field_defn, path: next_path, query: query, object: object, arguments: kwarg_arguments}) do
219
- field_defn.resolve(object, kwarg_arguments, context)
220
- end
209
+ query.trace("execute_field", {owner: owner_type, field: field_defn, path: next_path, query: query, object: object, arguments: kwarg_arguments}) do
210
+ field_defn.resolve(object, kwarg_arguments, context)
221
211
  end
222
212
  rescue GraphQL::ExecutionError => err
223
213
  err
224
214
  end
225
- after_lazy(app_result, owner: owner_type, field: field_defn, path: next_path, scoped_context: context.scoped_context, owner_object: object, arguments: kwarg_arguments) do |inner_result|
215
+ after_lazy(app_result, owner: owner_type, field: field_defn, path: next_path, owner_object: object, arguments: kwarg_arguments) do |inner_result|
226
216
  continue_value = continue_value(next_path, inner_result, field_defn, return_type.non_null?, ast_node)
227
217
  if HALT != continue_value
228
218
  continue_field(next_path, continue_value, field_defn, return_type, ast_node, next_selections, false, object, kwarg_arguments)
@@ -296,7 +286,7 @@ module GraphQL
296
286
  r
297
287
  when "UNION", "INTERFACE"
298
288
  resolved_type_or_lazy = query.resolve_type(type, value)
299
- after_lazy(resolved_type_or_lazy, owner: type, path: path, scoped_context: context.scoped_context, field: field, owner_object: owner_object, arguments: arguments) do |resolved_type|
289
+ after_lazy(resolved_type_or_lazy, owner: type, path: path, field: field, owner_object: owner_object, arguments: arguments) do |resolved_type|
300
290
  possible_types = query.possible_types(type)
301
291
 
302
292
  if !possible_types.include?(resolved_type)
@@ -316,12 +306,12 @@ module GraphQL
316
306
  rescue GraphQL::ExecutionError => err
317
307
  err
318
308
  end
319
- after_lazy(object_proxy, owner: type, path: path, scoped_context: context.scoped_context, field: field, owner_object: owner_object, arguments: arguments) do |inner_object|
309
+ after_lazy(object_proxy, owner: type, path: path, field: field, owner_object: owner_object, arguments: arguments) do |inner_object|
320
310
  continue_value = continue_value(path, inner_object, field, is_non_null, ast_node)
321
311
  if HALT != continue_value
322
312
  response_hash = {}
323
313
  write_in_response(path, response_hash)
324
- evaluate_selections(path, context.scoped_context, continue_value, type, next_selections)
314
+ evaluate_selections(path, continue_value, type, next_selections)
325
315
  response_hash
326
316
  end
327
317
  end
@@ -330,7 +320,6 @@ module GraphQL
330
320
  write_in_response(path, response_list)
331
321
  inner_type = type.of_type
332
322
  idx = 0
333
- scoped_context = context.scoped_context
334
323
  value.each do |inner_value|
335
324
  next_path = path.dup
336
325
  next_path << idx
@@ -338,7 +327,7 @@ module GraphQL
338
327
  idx += 1
339
328
  set_type_at_path(next_path, inner_type)
340
329
  # This will update `response_list` with the lazy
341
- after_lazy(inner_value, owner: inner_type, path: next_path, scoped_context: scoped_context, field: field, owner_object: owner_object, arguments: arguments) do |inner_inner_value|
330
+ after_lazy(inner_value, owner: inner_type, path: next_path, field: field, owner_object: owner_object, arguments: arguments) do |inner_inner_value|
342
331
  # reset `is_non_null` here and below, because the inner type will have its own nullability constraint
343
332
  continue_value = continue_value(next_path, inner_inner_value, field, false, ast_node)
344
333
  if HALT != continue_value
@@ -404,30 +393,23 @@ module GraphQL
404
393
  # @param field [GraphQL::Schema::Field]
405
394
  # @param eager [Boolean] Set to `true` for mutation root fields only
406
395
  # @return [GraphQL::Execution::Lazy, Object] If loading `object` will be deferred, it's a wrapper over it.
407
- def after_lazy(lazy_obj, owner:, field:, path:, scoped_context:, owner_object:, arguments:, eager: false)
408
- @interpreter_context[:current_object] = owner_object
409
- @interpreter_context[:current_arguments] = arguments
396
+ def after_lazy(lazy_obj, owner:, field:, path:, owner_object:, arguments:, eager: false)
410
397
  @interpreter_context[:current_path] = path
411
398
  @interpreter_context[:current_field] = field
412
399
  if schema.lazy?(lazy_obj)
413
400
  lazy = GraphQL::Execution::Lazy.new(path: path, field: field) do
414
401
  @interpreter_context[:current_path] = path
415
402
  @interpreter_context[:current_field] = field
416
- @interpreter_context[:current_object] = owner_object
417
- @interpreter_context[:current_arguments] = arguments
418
- context.scoped_context = scoped_context
419
403
  # Wrap the execution of _this_ method with tracing,
420
404
  # but don't wrap the continuation below
421
405
  inner_obj = begin
422
- query.with_error_handling do
423
- query.trace("execute_field_lazy", {owner: owner, field: field, path: path, query: query, object: owner_object, arguments: arguments}) do
424
- schema.sync_lazy(lazy_obj)
425
- end
406
+ query.trace("execute_field_lazy", {owner: owner, field: field, path: path, query: query, object: owner_object, arguments: arguments}) do
407
+ schema.sync_lazy(lazy_obj)
426
408
  end
427
409
  rescue GraphQL::ExecutionError, GraphQL::UnauthorizedError => err
428
410
  yield(err)
429
411
  end
430
- after_lazy(inner_obj, owner: owner, field: field, path: path, scoped_context: context.scoped_context, owner_object: owner_object, arguments: arguments, eager: eager) do |really_inner_obj|
412
+ after_lazy(inner_obj, owner: owner, field: field, path: path, owner_object: owner_object, arguments: arguments, eager: eager) do |really_inner_obj|
431
413
  yield(really_inner_obj)
432
414
  end
433
415
  end
@@ -518,11 +500,7 @@ module GraphQL
518
500
  args = arguments(nil, arg_type, ast_value)
519
501
  # We're not tracking defaults_used, but for our purposes
520
502
  # we compare the value to the default value.
521
-
522
- input_obj = query.with_error_handling do
523
- arg_type.new(ruby_kwargs: args, context: context, defaults_used: nil)
524
- end
525
- return true, input_obj
503
+ return true, arg_type.new(ruby_kwargs: args, context: context, defaults_used: nil)
526
504
  else
527
505
  flat_value = flatten_ast_value(ast_value)
528
506
  return true, arg_type.coerce_input(flat_value, context)
@@ -44,9 +44,9 @@ module GraphQL
44
44
  end
45
45
 
46
46
  class << self
47
- def run_all(schema, query_options, **kwargs)
48
- queries = query_options.map { |opts| GraphQL::Query.new(schema, nil, **opts) }
49
- run_queries(schema, queries, **kwargs)
47
+ def run_all(schema, query_options, *args)
48
+ queries = query_options.map { |opts| GraphQL::Query.new(schema, nil, opts) }
49
+ run_queries(schema, queries, *args)
50
50
  end
51
51
 
52
52
  # @param schema [GraphQL::Schema]
@@ -196,6 +196,10 @@ module GraphQL
196
196
 
197
197
  attr_accessor :ast_node
198
198
 
199
+ # Future-compatible alias
200
+ # @see {GraphQL::SchemaMember}
201
+ alias :graphql_definition :itself
202
+
199
203
  # @return [Boolean]
200
204
  def connection?
201
205
  @connection
@@ -315,6 +319,10 @@ module GraphQL
315
319
  }
316
320
  end
317
321
 
322
+ def type_class
323
+ metadata[:type_class]
324
+ end
325
+
318
326
  private
319
327
 
320
328
  def build_default_resolver
@@ -33,7 +33,7 @@ module GraphQL
33
33
  end
34
34
 
35
35
  def self.build(onlies)
36
- case onlies
36
+ case onlies.size
37
37
  when 0
38
38
  nil
39
39
  when 1
@@ -43,7 +43,7 @@ module GraphQL
43
43
 
44
44
  # @return [Object] This function's resolver
45
45
  def call(obj, args, ctx)
46
- raise GraphQL::RequiredImplementationMissingError
46
+ raise NotImplementedError
47
47
  end
48
48
 
49
49
  # @return [String, nil]
@@ -99,8 +99,7 @@ module GraphQL
99
99
  end
100
100
  end
101
101
 
102
- result = arguments_class.new(input_values, context: ctx, defaults_used: defaults_used)
103
- result.prepare
102
+ arguments_class.new(input_values, context: ctx, defaults_used: defaults_used)
104
103
  end
105
104
 
106
105
  # @api private
@@ -15,9 +15,8 @@ module GraphQL
15
15
  end
16
16
 
17
17
  def __type(name:)
18
- return unless context.warden.reachable_type?(name)
19
-
20
18
  type = context.warden.get_type(name)
19
+
21
20
  if type && context.interpreter?
22
21
  type = type.metadata[:type_class] || raise("Invariant: interpreter requires class-based type for #{name}")
23
22
  end
@@ -18,20 +18,38 @@ module GraphQL
18
18
  'null'
19
19
  else
20
20
  coerced_default_value = @object.type.coerce_result(value, @context)
21
- if @object.type.unwrap.is_a?(GraphQL::EnumType)
22
- if @object.type.list?
23
- "[#{coerced_default_value.join(", ")}]"
24
- else
25
- coerced_default_value
26
- end
27
- else
28
- GraphQL::Language.serialize(coerced_default_value)
29
- end
21
+ serialize_default_value(coerced_default_value, @object.type)
30
22
  end
31
23
  else
32
24
  nil
33
25
  end
34
26
  end
27
+
28
+
29
+ private
30
+
31
+ # Recursively serialize, taking care not to add quotes to enum values
32
+ def serialize_default_value(value, type)
33
+ if value.nil?
34
+ 'null'
35
+ elsif type.kind.list?
36
+ inner_type = type.of_type
37
+ "[" + value.map { |v| serialize_default_value(v, inner_type) }.join(", ") + "]"
38
+ elsif type.kind.non_null?
39
+ serialize_default_value(value, type.of_type)
40
+ elsif type.kind.enum?
41
+ value
42
+ elsif type.kind.input_object?
43
+ "{" +
44
+ value.map do |k, v|
45
+ arg_defn = type.arguments[k]
46
+ "#{k}: #{serialize_default_value(v, arg_defn.type)}"
47
+ end.join(", ") +
48
+ "}"
49
+ else
50
+ GraphQL::Language.serialize(value)
51
+ end
52
+ end
35
53
  end
36
54
  end
37
55
  end
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  module GraphQL
4
3
  module Introspection
5
4
  class SchemaType < Introspection::BaseObject
@@ -15,7 +14,7 @@ module GraphQL
15
14
  field :directives, [GraphQL::Schema::LateBoundType.new("__Directive")], "A list of all directives supported by this server.", null: false
16
15
 
17
16
  def types
18
- types = @context.warden.reachable_types.sort_by(&:graphql_name)
17
+ types = @context.warden.types
19
18
  if context.interpreter?
20
19
  types.map { |t| t.metadata[:type_class] || raise("Invariant: can't introspect non-class-based type: #{t}") }
21
20
  else
@@ -32,10 +32,10 @@ module GraphQL
32
32
  end
33
33
 
34
34
  # Remove leading & trailing blank lines
35
- while lines.size > 0 && lines[0].empty?
35
+ while lines.first.empty?
36
36
  lines.shift
37
37
  end
38
- while lines.size > 0 && lines[-1].empty?
38
+ while lines.last.empty?
39
39
  lines.pop
40
40
  end
41
41
 
@@ -23,16 +23,10 @@ module GraphQL
23
23
  @include_built_in_scalars = include_built_in_scalars
24
24
  @include_built_in_directives = include_built_in_directives
25
25
 
26
- filter = GraphQL::Filter.new(only: only, except: except)
27
- if @schema.respond_to?(:visible?)
28
- filter = filter.merge(only: @schema.method(:visible?))
29
- end
30
-
31
- schema_context = schema.context_class.new(query: nil, object: nil, schema: schema, values: context)
32
26
  @warden = GraphQL::Schema::Warden.new(
33
- filter,
27
+ GraphQL::Filter.new(only: only, except: except),
34
28
  schema: @schema,
35
- context: schema_context,
29
+ context: context,
36
30
  )
37
31
  end
38
32
 
@@ -156,7 +150,7 @@ module GraphQL
156
150
 
157
151
  def build_directive_node(directive)
158
152
  GraphQL::Language::Nodes::DirectiveDefinition.new(
159
- name: directive.name,
153
+ name: directive.graphql_name,
160
154
  arguments: build_argument_nodes(warden.arguments(directive)),
161
155
  locations: build_directive_location_nodes(directive.locations),
162
156
  description: directive.description,
@@ -213,7 +207,7 @@ module GraphQL
213
207
  when ListType
214
208
  default_value.to_a.map { |v| build_default_value(v, type.of_type) }
215
209
  else
216
- raise GraphQL::RequiredImplementationMissingError, "Unexpected default value type #{type.inspect}"
210
+ raise NotImplementedError, "Unexpected default value type #{type.inspect}"
217
211
  end
218
212
  end
219
213
 
@@ -256,7 +250,7 @@ module GraphQL
256
250
  definitions = []
257
251
  definitions << build_schema_node if include_schema_node?
258
252
  definitions += build_directive_nodes(warden.directives)
259
- definitions += build_type_definition_nodes(warden.reachable_types)
253
+ definitions += build_type_definition_nodes(warden.types)
260
254
  definitions
261
255
  end
262
256
 
@@ -314,7 +314,7 @@ def self.run_lexer(query_string)
314
314
  begin
315
315
  te = p+1;
316
316
  begin
317
- emit(:RCURLY, ts, te, meta, "}")
317
+ emit(:RCURLY, ts, te, meta)
318
318
  end
319
319
 
320
320
  end
@@ -328,7 +328,7 @@ def self.run_lexer(query_string)
328
328
  begin
329
329
  te = p+1;
330
330
  begin
331
- emit(:LCURLY, ts, te, meta, "{")
331
+ emit(:LCURLY, ts, te, meta)
332
332
  end
333
333
 
334
334
  end
@@ -342,7 +342,7 @@ def self.run_lexer(query_string)
342
342
  begin
343
343
  te = p+1;
344
344
  begin
345
- emit(:RPAREN, ts, te, meta, ")")
345
+ emit(:RPAREN, ts, te, meta)
346
346
  end
347
347
 
348
348
  end
@@ -356,7 +356,7 @@ def self.run_lexer(query_string)
356
356
  begin
357
357
  te = p+1;
358
358
  begin
359
- emit(:LPAREN, ts, te, meta, "(")
359
+ emit(:LPAREN, ts, te, meta)
360
360
  end
361
361
 
362
362
  end
@@ -370,7 +370,7 @@ def self.run_lexer(query_string)
370
370
  begin
371
371
  te = p+1;
372
372
  begin
373
- emit(:RBRACKET, ts, te, meta, "]")
373
+ emit(:RBRACKET, ts, te, meta)
374
374
  end
375
375
 
376
376
  end
@@ -384,7 +384,7 @@ def self.run_lexer(query_string)
384
384
  begin
385
385
  te = p+1;
386
386
  begin
387
- emit(:LBRACKET, ts, te, meta, "[")
387
+ emit(:LBRACKET, ts, te, meta)
388
388
  end
389
389
 
390
390
  end
@@ -398,7 +398,7 @@ def self.run_lexer(query_string)
398
398
  begin
399
399
  te = p+1;
400
400
  begin
401
- emit(:COLON, ts, te, meta, ":")
401
+ emit(:COLON, ts, te, meta)
402
402
  end
403
403
 
404
404
  end
@@ -440,7 +440,7 @@ def self.run_lexer(query_string)
440
440
  begin
441
441
  te = p+1;
442
442
  begin
443
- emit(:VAR_SIGN, ts, te, meta, "$")
443
+ emit(:VAR_SIGN, ts, te, meta)
444
444
  end
445
445
 
446
446
  end
@@ -454,7 +454,7 @@ def self.run_lexer(query_string)
454
454
  begin
455
455
  te = p+1;
456
456
  begin
457
- emit(:DIR_SIGN, ts, te, meta, "@")
457
+ emit(:DIR_SIGN, ts, te, meta)
458
458
  end
459
459
 
460
460
  end
@@ -468,7 +468,7 @@ def self.run_lexer(query_string)
468
468
  begin
469
469
  te = p+1;
470
470
  begin
471
- emit(:ELLIPSIS, ts, te, meta, "...")
471
+ emit(:ELLIPSIS, ts, te, meta)
472
472
  end
473
473
 
474
474
  end
@@ -482,7 +482,7 @@ def self.run_lexer(query_string)
482
482
  begin
483
483
  te = p+1;
484
484
  begin
485
- emit(:EQUALS, ts, te, meta, "=")
485
+ emit(:EQUALS, ts, te, meta)
486
486
  end
487
487
 
488
488
  end
@@ -496,7 +496,7 @@ def self.run_lexer(query_string)
496
496
  begin
497
497
  te = p+1;
498
498
  begin
499
- emit(:BANG, ts, te, meta, "!")
499
+ emit(:BANG, ts, te, meta)
500
500
  end
501
501
 
502
502
  end
@@ -510,7 +510,7 @@ def self.run_lexer(query_string)
510
510
  begin
511
511
  te = p+1;
512
512
  begin
513
- emit(:PIPE, ts, te, meta, "|")
513
+ emit(:PIPE, ts, te, meta)
514
514
  end
515
515
 
516
516
  end
@@ -524,7 +524,7 @@ def self.run_lexer(query_string)
524
524
  begin
525
525
  te = p+1;
526
526
  begin
527
- emit(:AMP, ts, te, meta, "&")
527
+ emit(:AMP, ts, te, meta)
528
528
  end
529
529
 
530
530
  end
@@ -738,7 +738,7 @@ def self.run_lexer(query_string)
738
738
  begin
739
739
  p = ((te))-1;
740
740
  begin
741
- emit(:ON, ts, te, meta, "on")
741
+ emit(:ON, ts, te, meta)
742
742
  end
743
743
 
744
744
  end
@@ -746,7 +746,7 @@ def self.run_lexer(query_string)
746
746
  begin
747
747
  p = ((te))-1;
748
748
  begin
749
- emit(:FRAGMENT, ts, te, meta, "fragment")
749
+ emit(:FRAGMENT, ts, te, meta)
750
750
  end
751
751
 
752
752
  end
@@ -754,7 +754,7 @@ def self.run_lexer(query_string)
754
754
  begin
755
755
  p = ((te))-1;
756
756
  begin
757
- emit(:TRUE, ts, te, meta, "true")
757
+ emit(:TRUE, ts, te, meta)
758
758
  end
759
759
 
760
760
  end
@@ -762,7 +762,7 @@ def self.run_lexer(query_string)
762
762
  begin
763
763
  p = ((te))-1;
764
764
  begin
765
- emit(:FALSE, ts, te, meta, "false")
765
+ emit(:FALSE, ts, te, meta)
766
766
  end
767
767
 
768
768
  end
@@ -770,7 +770,7 @@ def self.run_lexer(query_string)
770
770
  begin
771
771
  p = ((te))-1;
772
772
  begin
773
- emit(:NULL, ts, te, meta, "null")
773
+ emit(:NULL, ts, te, meta)
774
774
  end
775
775
 
776
776
  end
@@ -778,7 +778,7 @@ def self.run_lexer(query_string)
778
778
  begin
779
779
  p = ((te))-1;
780
780
  begin
781
- emit(:QUERY, ts, te, meta, "query")
781
+ emit(:QUERY, ts, te, meta)
782
782
  end
783
783
 
784
784
  end
@@ -786,7 +786,7 @@ def self.run_lexer(query_string)
786
786
  begin
787
787
  p = ((te))-1;
788
788
  begin
789
- emit(:MUTATION, ts, te, meta, "mutation")
789
+ emit(:MUTATION, ts, te, meta)
790
790
  end
791
791
 
792
792
  end
@@ -794,7 +794,7 @@ def self.run_lexer(query_string)
794
794
  begin
795
795
  p = ((te))-1;
796
796
  begin
797
- emit(:SUBSCRIPTION, ts, te, meta, "subscription")
797
+ emit(:SUBSCRIPTION, ts, te, meta)
798
798
  end
799
799
 
800
800
  end
@@ -1371,11 +1371,11 @@ end
1371
1371
 
1372
1372
  def self.record_comment(ts, te, meta)
1373
1373
  token = GraphQL::Language::Token.new(
1374
- :COMMENT,
1375
- meta[:data][ts, te - ts].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING),
1376
- meta[:line],
1377
- meta[:col],
1378
- meta[:previous_token],
1374
+ name: :COMMENT,
1375
+ value: meta[:data][ts, te - ts].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING),
1376
+ line: meta[:line],
1377
+ col: meta[:col],
1378
+ prev_token: meta[:previous_token],
1379
1379
  )
1380
1380
 
1381
1381
  meta[:previous_token] = token
@@ -1383,14 +1383,13 @@ meta[:previous_token] = token
1383
1383
  meta[:col] += te - ts
1384
1384
  end
1385
1385
 
1386
- def self.emit(token_name, ts, te, meta, token_value = nil)
1387
- token_value ||= meta[:data][ts, te - ts].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING)
1386
+ def self.emit(token_name, ts, te, meta)
1388
1387
  meta[:tokens] << token = GraphQL::Language::Token.new(
1389
- token_name,
1390
- token_value,
1391
- meta[:line],
1392
- meta[:col],
1393
- meta[:previous_token],
1388
+ name: token_name,
1389
+ value: meta[:data][ts, te - ts].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING),
1390
+ line: meta[:line],
1391
+ col: meta[:col],
1392
+ prev_token: meta[:previous_token],
1394
1393
  )
1395
1394
  meta[:previous_token] = token
1396
1395
  # Bump the column counter for the next token
@@ -1429,30 +1428,30 @@ end
1429
1428
  # (It's faster: https://bugs.ruby-lang.org/issues/8110)
1430
1429
  if !value.valid_encoding? || value !~ VALID_STRING
1431
1430
  meta[:tokens] << token = GraphQL::Language::Token.new(
1432
- :BAD_UNICODE_ESCAPE,
1433
- value,
1434
- meta[:line],
1435
- meta[:col],
1436
- meta[:previous_token],
1431
+ name: :BAD_UNICODE_ESCAPE,
1432
+ value: value,
1433
+ line: meta[:line],
1434
+ col: meta[:col],
1435
+ prev_token: meta[:previous_token],
1437
1436
  )
1438
1437
  else
1439
1438
  replace_escaped_characters_in_place(value)
1440
1439
 
1441
1440
  if !value.valid_encoding?
1442
1441
  meta[:tokens] << token = GraphQL::Language::Token.new(
1443
- :BAD_UNICODE_ESCAPE,
1444
- value,
1445
- meta[:line],
1446
- meta[:col],
1447
- meta[:previous_token],
1442
+ name: :BAD_UNICODE_ESCAPE,
1443
+ value: value,
1444
+ line: meta[:line],
1445
+ col: meta[:col],
1446
+ prev_token: meta[:previous_token],
1448
1447
  )
1449
1448
  else
1450
1449
  meta[:tokens] << token = GraphQL::Language::Token.new(
1451
- :STRING,
1452
- value,
1453
- meta[:line],
1454
- meta[:col],
1455
- meta[:previous_token],
1450
+ name: :STRING,
1451
+ value: value,
1452
+ line: meta[:line],
1453
+ col: meta[:col],
1454
+ prev_token: meta[:previous_token],
1456
1455
  )
1457
1456
  end
1458
1457
  end