graphql 2.0.27 → 2.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/install/templates/base_mutation.erb +2 -0
- data/lib/generators/graphql/install/templates/mutation_type.erb +2 -0
- data/lib/generators/graphql/install_generator.rb +3 -0
- data/lib/generators/graphql/templates/base_argument.erb +2 -0
- data/lib/generators/graphql/templates/base_connection.erb +2 -0
- data/lib/generators/graphql/templates/base_edge.erb +2 -0
- data/lib/generators/graphql/templates/base_enum.erb +2 -0
- data/lib/generators/graphql/templates/base_field.erb +2 -0
- data/lib/generators/graphql/templates/base_input_object.erb +2 -0
- data/lib/generators/graphql/templates/base_interface.erb +2 -0
- data/lib/generators/graphql/templates/base_object.erb +2 -0
- data/lib/generators/graphql/templates/base_resolver.erb +6 -0
- data/lib/generators/graphql/templates/base_scalar.erb +2 -0
- data/lib/generators/graphql/templates/base_union.erb +2 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +2 -0
- data/lib/generators/graphql/templates/loader.erb +2 -0
- data/lib/generators/graphql/templates/mutation.erb +2 -0
- data/lib/generators/graphql/templates/node_type.erb +2 -0
- data/lib/generators/graphql/templates/query_type.erb +2 -0
- data/lib/generators/graphql/templates/schema.erb +2 -0
- data/lib/graphql/analysis/ast/analyzer.rb +7 -0
- data/lib/graphql/analysis/ast/field_usage.rb +32 -7
- data/lib/graphql/analysis/ast/query_complexity.rb +80 -128
- data/lib/graphql/analysis/ast/query_depth.rb +7 -2
- data/lib/graphql/analysis/ast/visitor.rb +2 -2
- data/lib/graphql/analysis/ast.rb +21 -11
- data/lib/graphql/backtrace/trace.rb +12 -15
- data/lib/graphql/coercion_error.rb +1 -9
- data/lib/graphql/dataloader/async_dataloader.rb +85 -0
- data/lib/graphql/dataloader/source.rb +11 -3
- data/lib/graphql/dataloader.rb +109 -142
- data/lib/graphql/duration_encoding_error.rb +16 -0
- data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +170 -0
- data/lib/graphql/execution/interpreter/runtime.rb +70 -248
- data/lib/graphql/execution/interpreter.rb +91 -157
- data/lib/graphql/execution/lookahead.rb +88 -21
- data/lib/graphql/introspection/dynamic_fields.rb +1 -1
- data/lib/graphql/introspection/entry_points.rb +11 -5
- data/lib/graphql/introspection/schema_type.rb +3 -1
- data/lib/graphql/language/block_string.rb +34 -18
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/document_from_schema_definition.rb +37 -37
- data/lib/graphql/language/lexer.rb +271 -177
- data/lib/graphql/language/nodes.rb +74 -56
- data/lib/graphql/language/parser.rb +697 -1986
- data/lib/graphql/language/printer.rb +299 -146
- data/lib/graphql/language/sanitized_printer.rb +20 -22
- data/lib/graphql/language/static_visitor.rb +167 -0
- data/lib/graphql/language/visitor.rb +20 -81
- data/lib/graphql/language.rb +1 -0
- data/lib/graphql/load_application_object_failed_error.rb +5 -1
- data/lib/graphql/pagination/array_connection.rb +3 -3
- data/lib/graphql/pagination/connection.rb +28 -1
- data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -2
- data/lib/graphql/pagination/relation_connection.rb +3 -3
- data/lib/graphql/query/context/scoped_context.rb +101 -0
- data/lib/graphql/query/context.rb +36 -98
- data/lib/graphql/query/null_context.rb +4 -11
- data/lib/graphql/query/validation_pipeline.rb +2 -2
- data/lib/graphql/query/variables.rb +3 -3
- data/lib/graphql/query.rb +13 -22
- data/lib/graphql/railtie.rb +9 -6
- data/lib/graphql/rake_task.rb +3 -12
- data/lib/graphql/schema/argument.rb +6 -1
- data/lib/graphql/schema/build_from_definition.rb +0 -11
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/specified_by.rb +14 -0
- data/lib/graphql/schema/directive.rb +1 -1
- data/lib/graphql/schema/enum.rb +3 -3
- data/lib/graphql/schema/field/connection_extension.rb +1 -15
- data/lib/graphql/schema/field/scope_extension.rb +8 -1
- data/lib/graphql/schema/field.rb +8 -5
- data/lib/graphql/schema/has_single_input_argument.rb +156 -0
- data/lib/graphql/schema/input_object.rb +2 -2
- data/lib/graphql/schema/interface.rb +10 -10
- data/lib/graphql/schema/introspection_system.rb +2 -0
- data/lib/graphql/schema/loader.rb +0 -2
- data/lib/graphql/schema/member/base_dsl_methods.rb +2 -1
- data/lib/graphql/schema/member/has_arguments.rb +61 -38
- data/lib/graphql/schema/member/has_fields.rb +8 -5
- data/lib/graphql/schema/member/has_interfaces.rb +23 -9
- data/lib/graphql/schema/member/scoped.rb +19 -0
- data/lib/graphql/schema/member/validates_input.rb +3 -3
- data/lib/graphql/schema/object.rb +8 -0
- data/lib/graphql/schema/printer.rb +8 -7
- data/lib/graphql/schema/relay_classic_mutation.rb +6 -128
- data/lib/graphql/schema/resolver.rb +7 -3
- data/lib/graphql/schema/scalar.rb +3 -3
- data/lib/graphql/schema/subscription.rb +11 -4
- data/lib/graphql/schema/union.rb +1 -1
- data/lib/graphql/schema/warden.rb +96 -94
- data/lib/graphql/schema.rb +219 -72
- data/lib/graphql/static_validation/all_rules.rb +1 -1
- data/lib/graphql/static_validation/base_visitor.rb +1 -1
- data/lib/graphql/static_validation/literal_validator.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +1 -1
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +1 -1
- data/lib/graphql/static_validation/validation_context.rb +5 -5
- data/lib/graphql/static_validation/validator.rb +3 -0
- data/lib/graphql/static_validation.rb +0 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +3 -2
- data/lib/graphql/subscriptions/event.rb +8 -2
- data/lib/graphql/subscriptions.rb +14 -12
- data/lib/graphql/testing/helpers.rb +125 -0
- data/lib/graphql/testing.rb +2 -0
- data/lib/graphql/tracing/appoptics_trace.rb +2 -2
- data/lib/graphql/tracing/appoptics_tracing.rb +2 -2
- data/lib/graphql/tracing/data_dog_trace.rb +21 -34
- data/lib/graphql/tracing/data_dog_tracing.rb +7 -21
- data/lib/graphql/tracing/legacy_hooks_trace.rb +74 -0
- data/lib/graphql/tracing/platform_tracing.rb +2 -0
- data/lib/graphql/tracing/{prometheus_tracing → prometheus_trace}/graphql_collector.rb +3 -1
- data/lib/graphql/tracing/sentry_trace.rb +94 -0
- data/lib/graphql/tracing/trace.rb +1 -0
- data/lib/graphql/tracing.rb +3 -1
- data/lib/graphql/types/iso_8601_duration.rb +77 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +32 -2
- data/lib/graphql/types/relay/edge_behaviors.rb +7 -0
- data/lib/graphql/types.rb +1 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +3 -3
- data/readme.md +12 -2
- metadata +33 -25
- data/lib/graphql/deprecation.rb +0 -9
- data/lib/graphql/filter.rb +0 -59
- data/lib/graphql/language/parser.y +0 -560
- data/lib/graphql/static_validation/type_stack.rb +0 -216
- data/lib/graphql/subscriptions/instrumentation.rb +0 -28
@@ -16,30 +16,30 @@ module GraphQL
|
|
16
16
|
# @return [Integer] The first line of the definition (not the description)
|
17
17
|
attr_reader :definition_line
|
18
18
|
|
19
|
-
def initialize(
|
20
|
-
@definition_line =
|
21
|
-
super(
|
19
|
+
def initialize(definition_line: nil, **_rest)
|
20
|
+
@definition_line = definition_line
|
21
|
+
super(**_rest)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
attr_reader :
|
25
|
+
attr_reader :filename
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
def initialize(options = {})
|
31
|
-
if options.key?(:position_source)
|
32
|
-
position_source = options.delete(:position_source)
|
33
|
-
@line = position_source[1]
|
34
|
-
@col = position_source[2]
|
35
|
-
else
|
36
|
-
@line = options.delete(:line)
|
37
|
-
@col = options.delete(:col)
|
38
|
-
end
|
27
|
+
def line
|
28
|
+
@line ||= (@source_string && @pos) ? @source_string[0..@pos].count("\n") + 1 : nil
|
29
|
+
end
|
39
30
|
|
40
|
-
|
31
|
+
def col
|
32
|
+
@col ||= if @source_string && @pos
|
33
|
+
if @pos == 0
|
34
|
+
1
|
35
|
+
else
|
36
|
+
@source_string[0..@pos].split("\n").last.length
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
41
40
|
|
42
|
-
|
41
|
+
def definition_line
|
42
|
+
@definition_line ||= (@source_string && @definition_pos) ? @source_string[0..@definition_pos].count("\n") + 1 : nil
|
43
43
|
end
|
44
44
|
|
45
45
|
# Value equality
|
@@ -196,8 +196,8 @@ module GraphQL
|
|
196
196
|
module_eval <<-RUBY, __FILE__, __LINE__
|
197
197
|
# Singular method: create a node with these options
|
198
198
|
# and return a new `self` which includes that node in this list.
|
199
|
-
def merge_#{method_name.to_s.sub(/s$/, "")}(node_opts)
|
200
|
-
merge(#{method_name}: #{method_name} + [#{node_type.name}.new(node_opts)])
|
199
|
+
def merge_#{method_name.to_s.sub(/s$/, "")}(**node_opts)
|
200
|
+
merge(#{method_name}: #{method_name} + [#{node_type.name}.new(**node_opts)])
|
201
201
|
end
|
202
202
|
RUBY
|
203
203
|
end
|
@@ -226,13 +226,14 @@ module GraphQL
|
|
226
226
|
end
|
227
227
|
|
228
228
|
if defined?(@scalar_methods)
|
229
|
-
if
|
230
|
-
|
229
|
+
if !@initialize_was_generated
|
230
|
+
@initialize_was_generated = true
|
231
|
+
generate_initialize
|
231
232
|
else
|
232
233
|
# This method was defined manually
|
233
234
|
end
|
234
235
|
else
|
235
|
-
raise "Can't
|
236
|
+
raise "Can't generate_initialize because scalar_methods wasn't called; call it before children_methods"
|
236
237
|
end
|
237
238
|
end
|
238
239
|
|
@@ -261,7 +262,15 @@ module GraphQL
|
|
261
262
|
end
|
262
263
|
end
|
263
264
|
|
264
|
-
|
265
|
+
DEFAULT_INITIALIZE_OPTIONS = [
|
266
|
+
"line: nil",
|
267
|
+
"col: nil",
|
268
|
+
"pos: nil",
|
269
|
+
"filename: nil",
|
270
|
+
"source_string: nil",
|
271
|
+
]
|
272
|
+
|
273
|
+
def generate_initialize
|
265
274
|
scalar_method_names = @scalar_methods
|
266
275
|
# TODO: These probably should be scalar methods, but `types` returns an array
|
267
276
|
[:types, :description].each do |extra_method|
|
@@ -277,16 +286,27 @@ module GraphQL
|
|
277
286
|
return
|
278
287
|
else
|
279
288
|
arguments = scalar_method_names.map { |m| "#{m}: nil"} +
|
280
|
-
@children_methods.keys.map { |m| "#{m}: NO_CHILDREN" }
|
289
|
+
@children_methods.keys.map { |m| "#{m}: NO_CHILDREN" } +
|
290
|
+
DEFAULT_INITIALIZE_OPTIONS
|
281
291
|
|
282
292
|
assignments = scalar_method_names.map { |m| "@#{m} = #{m}"} +
|
283
293
|
@children_methods.keys.map { |m| "@#{m} = #{m}.freeze" }
|
284
294
|
|
295
|
+
if name.end_with?("Definition") && name != "FragmentDefinition"
|
296
|
+
arguments << "definition_pos: nil"
|
297
|
+
assignments << "@definition_pos = definition_pos"
|
298
|
+
end
|
299
|
+
|
285
300
|
keywords = scalar_method_names.map { |m| "#{m}: #{m}"} +
|
286
301
|
@children_methods.keys.map { |m| "#{m}: #{m}" }
|
287
302
|
|
288
303
|
module_eval <<-RUBY, __FILE__, __LINE__
|
289
|
-
def
|
304
|
+
def initialize(#{arguments.join(", ")})
|
305
|
+
@line = line
|
306
|
+
@col = col
|
307
|
+
@pos = pos
|
308
|
+
@filename = filename
|
309
|
+
@source_string = source_string
|
290
310
|
#{assignments.join("\n")}
|
291
311
|
end
|
292
312
|
|
@@ -323,7 +343,7 @@ module GraphQL
|
|
323
343
|
# @return [String, Float, Integer, Boolean, Array, InputObject, VariableIdentifier] The value passed for this key
|
324
344
|
|
325
345
|
def children
|
326
|
-
@children ||= Array(value).flatten.select { |v| v.is_a?(AbstractNode) }
|
346
|
+
@children ||= Array(value).flatten.tap { _1.select! { |v| v.is_a?(AbstractNode) } }
|
327
347
|
end
|
328
348
|
end
|
329
349
|
|
@@ -336,7 +356,6 @@ module GraphQL
|
|
336
356
|
end
|
337
357
|
|
338
358
|
class DirectiveDefinition < AbstractNode
|
339
|
-
include DefinitionNode
|
340
359
|
attr_reader :description
|
341
360
|
scalar_methods :name, :repeatable
|
342
361
|
children_methods(
|
@@ -365,17 +384,22 @@ module GraphQL
|
|
365
384
|
# @!attribute selections
|
366
385
|
# @return [Array<Nodes::Field>] Selections on this object (or empty array if this is a scalar field)
|
367
386
|
|
368
|
-
def
|
369
|
-
@name =
|
370
|
-
@arguments =
|
371
|
-
@directives =
|
372
|
-
@selections =
|
387
|
+
def initialize(name: nil, arguments: NONE, directives: NONE, selections: NONE, field_alias: nil, line: nil, col: nil, pos: nil, filename: nil, source_string: nil)
|
388
|
+
@name = name
|
389
|
+
@arguments = arguments || NONE
|
390
|
+
@directives = directives || NONE
|
391
|
+
@selections = selections || NONE
|
373
392
|
# oops, alias is a keyword:
|
374
|
-
@alias =
|
393
|
+
@alias = field_alias
|
394
|
+
@line = line
|
395
|
+
@col = col
|
396
|
+
@pos = pos
|
397
|
+
@filename = filename
|
398
|
+
@source_string = source_string
|
375
399
|
end
|
376
400
|
|
377
|
-
def self.from_a(filename, line, col,
|
378
|
-
self.new(filename: filename, line: line, col: col,
|
401
|
+
def self.from_a(filename, line, col, field_alias, name, arguments, directives, selections) # rubocop:disable Metrics/ParameterLists
|
402
|
+
self.new(filename: filename, line: line, col: col, field_alias: field_alias, name: name, arguments: arguments, directives: directives, selections: selections)
|
379
403
|
end
|
380
404
|
|
381
405
|
# Override this because default is `:fields`
|
@@ -384,29 +408,33 @@ module GraphQL
|
|
384
408
|
|
385
409
|
# A reusable fragment, defined at document-level.
|
386
410
|
class FragmentDefinition < AbstractNode
|
411
|
+
scalar_methods :name, :type
|
412
|
+
children_methods({
|
413
|
+
selections: GraphQL::Language::Nodes::Field,
|
414
|
+
directives: GraphQL::Language::Nodes::Directive,
|
415
|
+
})
|
416
|
+
|
417
|
+
self.children_method_name = :definitions
|
387
418
|
# @!attribute name
|
388
419
|
# @return [String] the identifier for this fragment, which may be applied with `...#{name}`
|
389
420
|
|
390
421
|
# @!attribute type
|
391
422
|
# @return [String] the type condition for this fragment (name of type which it may apply to)
|
392
|
-
def
|
423
|
+
def initialize(name: nil, type: nil, directives: NONE, selections: NONE, filename: nil, pos: nil, source_string: nil, line: nil, col: nil)
|
393
424
|
@name = name
|
394
425
|
@type = type
|
395
426
|
@directives = directives
|
396
427
|
@selections = selections
|
428
|
+
@filename = filename
|
429
|
+
@pos = pos
|
430
|
+
@source_string = source_string
|
431
|
+
@line = line
|
432
|
+
@col = col
|
397
433
|
end
|
398
434
|
|
399
435
|
def self.from_a(filename, line, col, name, type, directives, selections)
|
400
436
|
self.new(filename: filename, line: line, col: col, name: name, type: type, directives: directives, selections: selections)
|
401
437
|
end
|
402
|
-
|
403
|
-
scalar_methods :name, :type
|
404
|
-
children_methods({
|
405
|
-
selections: GraphQL::Language::Nodes::Field,
|
406
|
-
directives: GraphQL::Language::Nodes::Directive,
|
407
|
-
})
|
408
|
-
|
409
|
-
self.children_method_name = :definitions
|
410
438
|
end
|
411
439
|
|
412
440
|
# Application of a named fragment in a selection
|
@@ -535,7 +563,7 @@ module GraphQL
|
|
535
563
|
# @example Creating a custom string from a document
|
536
564
|
# class VariableScrubber < GraphQL::Language::Printer
|
537
565
|
# def print_argument(arg)
|
538
|
-
# "#{arg.name}: <HIDDEN>"
|
566
|
+
# print_string("#{arg.name}: <HIDDEN>")
|
539
567
|
# end
|
540
568
|
# end
|
541
569
|
#
|
@@ -562,7 +590,6 @@ module GraphQL
|
|
562
590
|
end
|
563
591
|
|
564
592
|
class SchemaDefinition < AbstractNode
|
565
|
-
include DefinitionNode
|
566
593
|
scalar_methods :query, :mutation, :subscription
|
567
594
|
children_methods({
|
568
595
|
directives: GraphQL::Language::Nodes::Directive,
|
@@ -579,7 +606,6 @@ module GraphQL
|
|
579
606
|
end
|
580
607
|
|
581
608
|
class ScalarTypeDefinition < AbstractNode
|
582
|
-
include DefinitionNode
|
583
609
|
attr_reader :description
|
584
610
|
scalar_methods :name
|
585
611
|
children_methods({
|
@@ -597,7 +623,6 @@ module GraphQL
|
|
597
623
|
end
|
598
624
|
|
599
625
|
class InputValueDefinition < AbstractNode
|
600
|
-
include DefinitionNode
|
601
626
|
attr_reader :description
|
602
627
|
scalar_methods :name, :type, :default_value
|
603
628
|
children_methods({
|
@@ -607,7 +632,6 @@ module GraphQL
|
|
607
632
|
end
|
608
633
|
|
609
634
|
class FieldDefinition < AbstractNode
|
610
|
-
include DefinitionNode
|
611
635
|
attr_reader :description
|
612
636
|
scalar_methods :name, :type
|
613
637
|
children_methods({
|
@@ -628,7 +652,6 @@ module GraphQL
|
|
628
652
|
end
|
629
653
|
|
630
654
|
class ObjectTypeDefinition < AbstractNode
|
631
|
-
include DefinitionNode
|
632
655
|
attr_reader :description
|
633
656
|
scalar_methods :name, :interfaces
|
634
657
|
children_methods({
|
@@ -648,7 +671,6 @@ module GraphQL
|
|
648
671
|
end
|
649
672
|
|
650
673
|
class InterfaceTypeDefinition < AbstractNode
|
651
|
-
include DefinitionNode
|
652
674
|
attr_reader :description
|
653
675
|
scalar_methods :name
|
654
676
|
children_methods({
|
@@ -670,7 +692,6 @@ module GraphQL
|
|
670
692
|
end
|
671
693
|
|
672
694
|
class UnionTypeDefinition < AbstractNode
|
673
|
-
include DefinitionNode
|
674
695
|
attr_reader :description, :types
|
675
696
|
scalar_methods :name
|
676
697
|
children_methods({
|
@@ -689,7 +710,6 @@ module GraphQL
|
|
689
710
|
end
|
690
711
|
|
691
712
|
class EnumValueDefinition < AbstractNode
|
692
|
-
include DefinitionNode
|
693
713
|
attr_reader :description
|
694
714
|
scalar_methods :name
|
695
715
|
children_methods({
|
@@ -699,7 +719,6 @@ module GraphQL
|
|
699
719
|
end
|
700
720
|
|
701
721
|
class EnumTypeDefinition < AbstractNode
|
702
|
-
include DefinitionNode
|
703
722
|
attr_reader :description
|
704
723
|
scalar_methods :name
|
705
724
|
children_methods({
|
@@ -719,7 +738,6 @@ module GraphQL
|
|
719
738
|
end
|
720
739
|
|
721
740
|
class InputObjectTypeDefinition < AbstractNode
|
722
|
-
include DefinitionNode
|
723
741
|
attr_reader :description
|
724
742
|
scalar_methods :name
|
725
743
|
children_methods({
|