tinygql 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/bench.rb +38 -0
- data/lib/tinygql/lexer.rb +118 -40
- data/lib/tinygql/nodes.rb +255 -86
- data/lib/tinygql/nodes.rb.erb +15 -2
- data/lib/tinygql/nodes.yml +34 -4
- data/lib/tinygql/parser.rb +156 -50
- data/lib/tinygql/version.rb +1 -1
- data/lib/tinygql/visitors.rb +261 -304
- data/lib/tinygql/visitors.rb.erb +8 -20
- data/test/lexer_test.rb +78 -0
- data/test/parser_test.rb +68 -0
- data/test/schema-extensions.graphql +48 -0
- metadata +4 -2
data/lib/tinygql/nodes.rb
CHANGED
@@ -3,45 +3,62 @@ module TinyGQL
|
|
3
3
|
class Node
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
6
|
+
# `pos` is the position of the _end_ of a token
|
7
|
+
attr_reader :pos
|
8
|
+
|
9
|
+
def initialize pos
|
10
|
+
@pos = pos
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return the line of this node given `doc`
|
14
|
+
def line doc
|
15
|
+
doc[0, @pos].count("\n") + 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def document?; false; end
|
19
|
+
def operation_definition?; false; end
|
20
|
+
def variable?; false; end
|
21
|
+
def named_type?; false; end
|
22
|
+
def not_null_type?; false; end
|
23
|
+
def list_type?; false; end
|
24
|
+
def variable_definition?; false; end
|
25
|
+
def value?; false; end
|
26
|
+
def argument?; false; end
|
27
|
+
def field?; false; end
|
28
|
+
def object_field?; false; end
|
29
|
+
def int_value?; false; end
|
30
|
+
def float_value?; false; end
|
31
|
+
def string_value?; false; end
|
32
|
+
def boolean_value?; false; end
|
33
|
+
def null_value?; false; end
|
34
|
+
def enum_value?; false; end
|
35
|
+
def list_value?; false; end
|
36
|
+
def object_value?; false; end
|
37
|
+
def directive?; false; end
|
38
|
+
def type_condition?; false; end
|
39
|
+
def inline_fragment?; false; end
|
40
|
+
def fragment_spread?; false; end
|
41
|
+
def fragment_definition?; false; end
|
42
|
+
def root_operation_type_definition?; false; end
|
43
|
+
def schema_definition?; false; end
|
44
|
+
def field_definition?; false; end
|
45
|
+
def input_value_definition?; false; end
|
46
|
+
def object_type_definition?; false; end
|
47
|
+
def interface_type_definition?; false; end
|
48
|
+
def union_type_definition?; false; end
|
49
|
+
def scalar_type_definition?; false; end
|
50
|
+
def enum_value_definition?; false; end
|
51
|
+
def enum_type_definition?; false; end
|
52
|
+
def input_object_type_definition?; false; end
|
53
|
+
def object_type_extension?; false; end
|
54
|
+
def executable_directive_location?; false; end
|
55
|
+
def type_system_directive_location?; false; end
|
56
|
+
def directive_definition?; false; end
|
57
|
+
def scalar_type_extension?; false; end
|
58
|
+
def interface_type_extension?; false; end
|
59
|
+
def union_type_extension?; false; end
|
60
|
+
def enum_type_extension?; false; end
|
61
|
+
def input_object_type_extension?; false; end
|
45
62
|
def each(&blk)
|
46
63
|
yield self
|
47
64
|
children.each { |v| v.each(&blk) }
|
@@ -51,7 +68,8 @@ module TinyGQL
|
|
51
68
|
class Document < Node
|
52
69
|
attr_reader :definitions
|
53
70
|
|
54
|
-
def initialize definitions
|
71
|
+
def initialize pos, definitions
|
72
|
+
super(pos)
|
55
73
|
@definitions = definitions
|
56
74
|
end
|
57
75
|
|
@@ -72,7 +90,8 @@ module TinyGQL
|
|
72
90
|
class OperationDefinition < Node
|
73
91
|
attr_reader :type, :name, :variable_definitions, :directives, :selection_set
|
74
92
|
|
75
|
-
def initialize type, name, variable_definitions, directives, selection_set
|
93
|
+
def initialize pos, type, name, variable_definitions, directives, selection_set
|
94
|
+
super(pos)
|
76
95
|
@type = type
|
77
96
|
@name = name
|
78
97
|
@variable_definitions = variable_definitions
|
@@ -97,7 +116,8 @@ module TinyGQL
|
|
97
116
|
class Variable < Node
|
98
117
|
attr_reader :name
|
99
118
|
|
100
|
-
def initialize name
|
119
|
+
def initialize pos, name
|
120
|
+
super(pos)
|
101
121
|
@name = name
|
102
122
|
end
|
103
123
|
|
@@ -118,7 +138,8 @@ module TinyGQL
|
|
118
138
|
class NamedType < Node
|
119
139
|
attr_reader :name
|
120
140
|
|
121
|
-
def initialize name
|
141
|
+
def initialize pos, name
|
142
|
+
super(pos)
|
122
143
|
@name = name
|
123
144
|
end
|
124
145
|
|
@@ -139,7 +160,8 @@ module TinyGQL
|
|
139
160
|
class NotNullType < Node
|
140
161
|
attr_reader :type
|
141
162
|
|
142
|
-
def initialize type
|
163
|
+
def initialize pos, type
|
164
|
+
super(pos)
|
143
165
|
@type = type
|
144
166
|
end
|
145
167
|
|
@@ -160,7 +182,8 @@ module TinyGQL
|
|
160
182
|
class ListType < Node
|
161
183
|
attr_reader :type
|
162
184
|
|
163
|
-
def initialize type
|
185
|
+
def initialize pos, type
|
186
|
+
super(pos)
|
164
187
|
@type = type
|
165
188
|
end
|
166
189
|
|
@@ -181,7 +204,8 @@ module TinyGQL
|
|
181
204
|
class VariableDefinition < Node
|
182
205
|
attr_reader :variable, :type, :default_value
|
183
206
|
|
184
|
-
def initialize variable, type, default_value
|
207
|
+
def initialize pos, variable, type, default_value
|
208
|
+
super(pos)
|
185
209
|
@variable = variable
|
186
210
|
@type = type
|
187
211
|
@default_value = default_value
|
@@ -204,7 +228,8 @@ module TinyGQL
|
|
204
228
|
class Value < Node
|
205
229
|
attr_reader :value
|
206
230
|
|
207
|
-
def initialize value
|
231
|
+
def initialize pos, value
|
232
|
+
super(pos)
|
208
233
|
@value = value
|
209
234
|
end
|
210
235
|
|
@@ -225,7 +250,8 @@ module TinyGQL
|
|
225
250
|
class Argument < Node
|
226
251
|
attr_reader :name, :value
|
227
252
|
|
228
|
-
def initialize name, value
|
253
|
+
def initialize pos, name, value
|
254
|
+
super(pos)
|
229
255
|
@name = name
|
230
256
|
@value = value
|
231
257
|
end
|
@@ -247,7 +273,8 @@ module TinyGQL
|
|
247
273
|
class Field < Node
|
248
274
|
attr_reader :aliaz, :name, :arguments, :directives, :selection_set
|
249
275
|
|
250
|
-
def initialize aliaz, name, arguments, directives, selection_set
|
276
|
+
def initialize pos, aliaz, name, arguments, directives, selection_set
|
277
|
+
super(pos)
|
251
278
|
@aliaz = aliaz
|
252
279
|
@name = name
|
253
280
|
@arguments = arguments
|
@@ -272,7 +299,8 @@ module TinyGQL
|
|
272
299
|
class ObjectField < Node
|
273
300
|
attr_reader :name, :value
|
274
301
|
|
275
|
-
def initialize name, value
|
302
|
+
def initialize pos, name, value
|
303
|
+
super(pos)
|
276
304
|
@name = name
|
277
305
|
@value = value
|
278
306
|
end
|
@@ -385,7 +413,8 @@ module TinyGQL
|
|
385
413
|
class ObjectValue < Node
|
386
414
|
attr_reader :values
|
387
415
|
|
388
|
-
def initialize values
|
416
|
+
def initialize pos, values
|
417
|
+
super(pos)
|
389
418
|
@values = values
|
390
419
|
end
|
391
420
|
|
@@ -406,7 +435,8 @@ module TinyGQL
|
|
406
435
|
class Directive < Node
|
407
436
|
attr_reader :name, :arguments
|
408
437
|
|
409
|
-
def initialize name, arguments
|
438
|
+
def initialize pos, name, arguments
|
439
|
+
super(pos)
|
410
440
|
@name = name
|
411
441
|
@arguments = arguments
|
412
442
|
end
|
@@ -422,13 +452,14 @@ module TinyGQL
|
|
422
452
|
def directive?; true; end
|
423
453
|
|
424
454
|
def children
|
425
|
-
ary = []; ary.concat(arguments); ary
|
455
|
+
ary = []; ary.concat(arguments) if arguments; ary
|
426
456
|
end
|
427
457
|
end
|
428
458
|
class TypeCondition < Node
|
429
459
|
attr_reader :named_type
|
430
460
|
|
431
|
-
def initialize named_type
|
461
|
+
def initialize pos, named_type
|
462
|
+
super(pos)
|
432
463
|
@named_type = named_type
|
433
464
|
end
|
434
465
|
|
@@ -449,7 +480,8 @@ module TinyGQL
|
|
449
480
|
class InlineFragment < Node
|
450
481
|
attr_reader :type_condition, :directives, :selection_set
|
451
482
|
|
452
|
-
def initialize type_condition, directives, selection_set
|
483
|
+
def initialize pos, type_condition, directives, selection_set
|
484
|
+
super(pos)
|
453
485
|
@type_condition = type_condition
|
454
486
|
@directives = directives
|
455
487
|
@selection_set = selection_set
|
@@ -472,7 +504,8 @@ module TinyGQL
|
|
472
504
|
class FragmentSpread < Node
|
473
505
|
attr_reader :fragment_name, :directives
|
474
506
|
|
475
|
-
def initialize fragment_name, directives
|
507
|
+
def initialize pos, fragment_name, directives
|
508
|
+
super(pos)
|
476
509
|
@fragment_name = fragment_name
|
477
510
|
@directives = directives
|
478
511
|
end
|
@@ -488,13 +521,14 @@ module TinyGQL
|
|
488
521
|
def fragment_spread?; true; end
|
489
522
|
|
490
523
|
def children
|
491
|
-
ary = []; ary
|
524
|
+
ary = []; ary.concat(directives) if directives; ary
|
492
525
|
end
|
493
526
|
end
|
494
527
|
class FragmentDefinition < Node
|
495
528
|
attr_reader :fragment_name, :type_condition, :directives, :selection_set
|
496
529
|
|
497
|
-
def initialize fragment_name, type_condition, directives, selection_set
|
530
|
+
def initialize pos, fragment_name, type_condition, directives, selection_set
|
531
|
+
super(pos)
|
498
532
|
@fragment_name = fragment_name
|
499
533
|
@type_condition = type_condition
|
500
534
|
@directives = directives
|
@@ -512,13 +546,14 @@ module TinyGQL
|
|
512
546
|
def fragment_definition?; true; end
|
513
547
|
|
514
548
|
def children
|
515
|
-
ary = []; ary <<
|
549
|
+
ary = []; ary << type_condition; ary.concat(directives) if directives; ary.concat(selection_set); ary
|
516
550
|
end
|
517
551
|
end
|
518
552
|
class RootOperationTypeDefinition < Node
|
519
553
|
attr_reader :operation_type, :named_type
|
520
554
|
|
521
|
-
def initialize operation_type, named_type
|
555
|
+
def initialize pos, operation_type, named_type
|
556
|
+
super(pos)
|
522
557
|
@operation_type = operation_type
|
523
558
|
@named_type = named_type
|
524
559
|
end
|
@@ -534,13 +569,14 @@ module TinyGQL
|
|
534
569
|
def root_operation_type_definition?; true; end
|
535
570
|
|
536
571
|
def children
|
537
|
-
ary = []; ary <<
|
572
|
+
ary = []; ary << named_type; ary
|
538
573
|
end
|
539
574
|
end
|
540
575
|
class SchemaDefinition < Node
|
541
576
|
attr_reader :description, :directives, :root_operation_definitions
|
542
577
|
|
543
|
-
def initialize description, directives, root_operation_definitions
|
578
|
+
def initialize pos, description, directives, root_operation_definitions
|
579
|
+
super(pos)
|
544
580
|
@description = description
|
545
581
|
@directives = directives
|
546
582
|
@root_operation_definitions = root_operation_definitions
|
@@ -557,13 +593,14 @@ module TinyGQL
|
|
557
593
|
def schema_definition?; true; end
|
558
594
|
|
559
595
|
def children
|
560
|
-
ary = []; ary.concat(directives) if directives; ary.concat(root_operation_definitions); ary
|
596
|
+
ary = []; ary << description if description; ary.concat(directives) if directives; ary.concat(root_operation_definitions); ary
|
561
597
|
end
|
562
598
|
end
|
563
599
|
class FieldDefinition < Node
|
564
600
|
attr_reader :description, :name, :arguments_definition, :type, :directives
|
565
601
|
|
566
|
-
def initialize description, name, arguments_definition, type, directives
|
602
|
+
def initialize pos, description, name, arguments_definition, type, directives
|
603
|
+
super(pos)
|
567
604
|
@description = description
|
568
605
|
@name = name
|
569
606
|
@arguments_definition = arguments_definition
|
@@ -582,13 +619,14 @@ module TinyGQL
|
|
582
619
|
def field_definition?; true; end
|
583
620
|
|
584
621
|
def children
|
585
|
-
ary = []; ary.concat(arguments_definition) if arguments_definition; ary << type; ary.concat(directives) if directives; ary
|
622
|
+
ary = []; ary << description if description; ary.concat(arguments_definition) if arguments_definition; ary << type; ary.concat(directives) if directives; ary
|
586
623
|
end
|
587
624
|
end
|
588
625
|
class InputValueDefinition < Node
|
589
626
|
attr_reader :description, :name, :type, :default_value, :directives
|
590
627
|
|
591
|
-
def initialize description, name, type, default_value, directives
|
628
|
+
def initialize pos, description, name, type, default_value, directives
|
629
|
+
super(pos)
|
592
630
|
@description = description
|
593
631
|
@name = name
|
594
632
|
@type = type
|
@@ -607,13 +645,14 @@ module TinyGQL
|
|
607
645
|
def input_value_definition?; true; end
|
608
646
|
|
609
647
|
def children
|
610
|
-
ary = []; ary << type; ary << default_value if default_value; ary.concat(directives) if directives; ary
|
648
|
+
ary = []; ary << description if description; ary << type; ary << default_value if default_value; ary.concat(directives) if directives; ary
|
611
649
|
end
|
612
650
|
end
|
613
651
|
class ObjectTypeDefinition < Node
|
614
652
|
attr_reader :description, :name, :implements_interfaces, :directives, :fields_definition
|
615
653
|
|
616
|
-
def initialize description, name, implements_interfaces, directives, fields_definition
|
654
|
+
def initialize pos, description, name, implements_interfaces, directives, fields_definition
|
655
|
+
super(pos)
|
617
656
|
@description = description
|
618
657
|
@name = name
|
619
658
|
@implements_interfaces = implements_interfaces
|
@@ -632,13 +671,14 @@ module TinyGQL
|
|
632
671
|
def object_type_definition?; true; end
|
633
672
|
|
634
673
|
def children
|
635
|
-
ary = []; ary.concat(implements_interfaces) if implements_interfaces; ary.concat(directives) if directives; ary.concat(fields_definition) if fields_definition; ary
|
674
|
+
ary = []; ary << description if description; ary.concat(implements_interfaces) if implements_interfaces; ary.concat(directives) if directives; ary.concat(fields_definition) if fields_definition; ary
|
636
675
|
end
|
637
676
|
end
|
638
677
|
class InterfaceTypeDefinition < Node
|
639
678
|
attr_reader :description, :name, :directives, :fields_definition
|
640
679
|
|
641
|
-
def initialize description, name, directives, fields_definition
|
680
|
+
def initialize pos, description, name, directives, fields_definition
|
681
|
+
super(pos)
|
642
682
|
@description = description
|
643
683
|
@name = name
|
644
684
|
@directives = directives
|
@@ -656,13 +696,14 @@ module TinyGQL
|
|
656
696
|
def interface_type_definition?; true; end
|
657
697
|
|
658
698
|
def children
|
659
|
-
ary = []; ary.concat(directives) if directives; ary.concat(fields_definition) if fields_definition; ary
|
699
|
+
ary = []; ary << description if description; ary.concat(directives) if directives; ary.concat(fields_definition) if fields_definition; ary
|
660
700
|
end
|
661
701
|
end
|
662
702
|
class UnionTypeDefinition < Node
|
663
703
|
attr_reader :description, :name, :directives, :union_member_types
|
664
704
|
|
665
|
-
def initialize description, name, directives, union_member_types
|
705
|
+
def initialize pos, description, name, directives, union_member_types
|
706
|
+
super(pos)
|
666
707
|
@description = description
|
667
708
|
@name = name
|
668
709
|
@directives = directives
|
@@ -680,13 +721,14 @@ module TinyGQL
|
|
680
721
|
def union_type_definition?; true; end
|
681
722
|
|
682
723
|
def children
|
683
|
-
ary = []; ary.concat(directives) if directives; ary.concat(union_member_types) if union_member_types; ary
|
724
|
+
ary = []; ary << description if description; ary.concat(directives) if directives; ary.concat(union_member_types) if union_member_types; ary
|
684
725
|
end
|
685
726
|
end
|
686
727
|
class ScalarTypeDefinition < Node
|
687
728
|
attr_reader :description, :name, :directives
|
688
729
|
|
689
|
-
def initialize description, name, directives
|
730
|
+
def initialize pos, description, name, directives
|
731
|
+
super(pos)
|
690
732
|
@description = description
|
691
733
|
@name = name
|
692
734
|
@directives = directives
|
@@ -703,13 +745,14 @@ module TinyGQL
|
|
703
745
|
def scalar_type_definition?; true; end
|
704
746
|
|
705
747
|
def children
|
706
|
-
ary = []; ary.concat(directives) if directives; ary
|
748
|
+
ary = []; ary << description if description; ary.concat(directives) if directives; ary
|
707
749
|
end
|
708
750
|
end
|
709
751
|
class EnumValueDefinition < Node
|
710
752
|
attr_reader :description, :enum_value, :directives
|
711
753
|
|
712
|
-
def initialize description, enum_value, directives
|
754
|
+
def initialize pos, description, enum_value, directives
|
755
|
+
super(pos)
|
713
756
|
@description = description
|
714
757
|
@enum_value = enum_value
|
715
758
|
@directives = directives
|
@@ -726,13 +769,14 @@ module TinyGQL
|
|
726
769
|
def enum_value_definition?; true; end
|
727
770
|
|
728
771
|
def children
|
729
|
-
ary = []; ary << enum_value; ary.concat(directives) if directives; ary
|
772
|
+
ary = []; ary << description if description; ary << enum_value; ary.concat(directives) if directives; ary
|
730
773
|
end
|
731
774
|
end
|
732
775
|
class EnumTypeDefinition < Node
|
733
776
|
attr_reader :description, :name, :directives, :enum_value_definition
|
734
777
|
|
735
|
-
def initialize description, name, directives, enum_value_definition
|
778
|
+
def initialize pos, description, name, directives, enum_value_definition
|
779
|
+
super(pos)
|
736
780
|
@description = description
|
737
781
|
@name = name
|
738
782
|
@directives = directives
|
@@ -750,13 +794,14 @@ module TinyGQL
|
|
750
794
|
def enum_type_definition?; true; end
|
751
795
|
|
752
796
|
def children
|
753
|
-
ary = []; ary.concat(directives) if directives; ary.concat(enum_value_definition) if enum_value_definition; ary
|
797
|
+
ary = []; ary << description if description; ary.concat(directives) if directives; ary.concat(enum_value_definition) if enum_value_definition; ary
|
754
798
|
end
|
755
799
|
end
|
756
800
|
class InputObjectTypeDefinition < Node
|
757
801
|
attr_reader :description, :name, :directives, :input_fields_definition
|
758
802
|
|
759
|
-
def initialize description, name, directives, input_fields_definition
|
803
|
+
def initialize pos, description, name, directives, input_fields_definition
|
804
|
+
super(pos)
|
760
805
|
@description = description
|
761
806
|
@name = name
|
762
807
|
@directives = directives
|
@@ -774,13 +819,14 @@ module TinyGQL
|
|
774
819
|
def input_object_type_definition?; true; end
|
775
820
|
|
776
821
|
def children
|
777
|
-
ary = []; ary.concat(directives) if directives; ary.concat(input_fields_definition) if input_fields_definition; ary
|
822
|
+
ary = []; ary << description if description; ary.concat(directives) if directives; ary.concat(input_fields_definition) if input_fields_definition; ary
|
778
823
|
end
|
779
824
|
end
|
780
825
|
class ObjectTypeExtension < Node
|
781
826
|
attr_reader :name, :implements_interfaces, :directives, :fields_definition
|
782
827
|
|
783
|
-
def initialize name, implements_interfaces, directives, fields_definition
|
828
|
+
def initialize pos, name, implements_interfaces, directives, fields_definition
|
829
|
+
super(pos)
|
784
830
|
@name = name
|
785
831
|
@implements_interfaces = implements_interfaces
|
786
832
|
@directives = directives
|
@@ -804,7 +850,8 @@ module TinyGQL
|
|
804
850
|
class ExecutableDirectiveLocation < Node
|
805
851
|
attr_reader :name
|
806
852
|
|
807
|
-
def initialize name
|
853
|
+
def initialize pos, name
|
854
|
+
super(pos)
|
808
855
|
@name = name
|
809
856
|
end
|
810
857
|
|
@@ -825,7 +872,8 @@ module TinyGQL
|
|
825
872
|
class TypeSystemDirectiveLocation < Node
|
826
873
|
attr_reader :name
|
827
874
|
|
828
|
-
def initialize name
|
875
|
+
def initialize pos, name
|
876
|
+
super(pos)
|
829
877
|
@name = name
|
830
878
|
end
|
831
879
|
|
@@ -846,7 +894,8 @@ module TinyGQL
|
|
846
894
|
class DirectiveDefinition < Node
|
847
895
|
attr_reader :description, :name, :arguments_definition, :directive_locations
|
848
896
|
|
849
|
-
def initialize description, name, arguments_definition, directive_locations
|
897
|
+
def initialize pos, description, name, arguments_definition, directive_locations
|
898
|
+
super(pos)
|
850
899
|
@description = description
|
851
900
|
@name = name
|
852
901
|
@arguments_definition = arguments_definition
|
@@ -864,7 +913,127 @@ module TinyGQL
|
|
864
913
|
def directive_definition?; true; end
|
865
914
|
|
866
915
|
def children
|
867
|
-
ary = []; ary.concat(arguments_definition) if arguments_definition; ary.concat(directive_locations); ary
|
916
|
+
ary = []; ary << description if description; ary.concat(arguments_definition) if arguments_definition; ary.concat(directive_locations); ary
|
917
|
+
end
|
918
|
+
end
|
919
|
+
class ScalarTypeExtension < Node
|
920
|
+
attr_reader :name, :directives
|
921
|
+
|
922
|
+
def initialize pos, name, directives
|
923
|
+
super(pos)
|
924
|
+
@name = name
|
925
|
+
@directives = directives
|
926
|
+
end
|
927
|
+
|
928
|
+
def accept viz
|
929
|
+
viz.handle_scalar_type_extension self
|
930
|
+
end
|
931
|
+
|
932
|
+
def fold viz, seed
|
933
|
+
viz.handle_scalar_type_extension self, seed
|
934
|
+
end
|
935
|
+
|
936
|
+
def scalar_type_extension?; true; end
|
937
|
+
|
938
|
+
def children
|
939
|
+
ary = []; ary.concat(directives) if directives; ary
|
940
|
+
end
|
941
|
+
end
|
942
|
+
class InterfaceTypeExtension < Node
|
943
|
+
attr_reader :name, :implements_interfaces, :directives, :fields_definition
|
944
|
+
|
945
|
+
def initialize pos, name, implements_interfaces, directives, fields_definition
|
946
|
+
super(pos)
|
947
|
+
@name = name
|
948
|
+
@implements_interfaces = implements_interfaces
|
949
|
+
@directives = directives
|
950
|
+
@fields_definition = fields_definition
|
951
|
+
end
|
952
|
+
|
953
|
+
def accept viz
|
954
|
+
viz.handle_interface_type_extension self
|
955
|
+
end
|
956
|
+
|
957
|
+
def fold viz, seed
|
958
|
+
viz.handle_interface_type_extension self, seed
|
959
|
+
end
|
960
|
+
|
961
|
+
def interface_type_extension?; true; end
|
962
|
+
|
963
|
+
def children
|
964
|
+
ary = []; ary.concat(implements_interfaces) if implements_interfaces; ary.concat(directives) if directives; ary.concat(fields_definition) if fields_definition; ary
|
965
|
+
end
|
966
|
+
end
|
967
|
+
class UnionTypeExtension < Node
|
968
|
+
attr_reader :name, :directives, :union_member_types
|
969
|
+
|
970
|
+
def initialize pos, name, directives, union_member_types
|
971
|
+
super(pos)
|
972
|
+
@name = name
|
973
|
+
@directives = directives
|
974
|
+
@union_member_types = union_member_types
|
975
|
+
end
|
976
|
+
|
977
|
+
def accept viz
|
978
|
+
viz.handle_union_type_extension self
|
979
|
+
end
|
980
|
+
|
981
|
+
def fold viz, seed
|
982
|
+
viz.handle_union_type_extension self, seed
|
983
|
+
end
|
984
|
+
|
985
|
+
def union_type_extension?; true; end
|
986
|
+
|
987
|
+
def children
|
988
|
+
ary = []; ary.concat(directives) if directives; ary.concat(union_member_types) if union_member_types; ary
|
989
|
+
end
|
990
|
+
end
|
991
|
+
class EnumTypeExtension < Node
|
992
|
+
attr_reader :name, :directives, :enum_value_definition
|
993
|
+
|
994
|
+
def initialize pos, name, directives, enum_value_definition
|
995
|
+
super(pos)
|
996
|
+
@name = name
|
997
|
+
@directives = directives
|
998
|
+
@enum_value_definition = enum_value_definition
|
999
|
+
end
|
1000
|
+
|
1001
|
+
def accept viz
|
1002
|
+
viz.handle_enum_type_extension self
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
def fold viz, seed
|
1006
|
+
viz.handle_enum_type_extension self, seed
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
def enum_type_extension?; true; end
|
1010
|
+
|
1011
|
+
def children
|
1012
|
+
ary = []; ary.concat(directives) if directives; ary.concat(enum_value_definition) if enum_value_definition; ary
|
1013
|
+
end
|
1014
|
+
end
|
1015
|
+
class InputObjectTypeExtension < Node
|
1016
|
+
attr_reader :name, :directives, :input_fields_definition
|
1017
|
+
|
1018
|
+
def initialize pos, name, directives, input_fields_definition
|
1019
|
+
super(pos)
|
1020
|
+
@name = name
|
1021
|
+
@directives = directives
|
1022
|
+
@input_fields_definition = input_fields_definition
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
def accept viz
|
1026
|
+
viz.handle_input_object_type_extension self
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
def fold viz, seed
|
1030
|
+
viz.handle_input_object_type_extension self, seed
|
1031
|
+
end
|
1032
|
+
|
1033
|
+
def input_object_type_extension?; true; end
|
1034
|
+
|
1035
|
+
def children
|
1036
|
+
ary = []; ary.concat(directives) if directives; ary.concat(input_fields_definition) if input_fields_definition; ary
|
868
1037
|
end
|
869
1038
|
end
|
870
1039
|
end
|
data/lib/tinygql/nodes.rb.erb
CHANGED
@@ -3,8 +3,20 @@ module TinyGQL
|
|
3
3
|
class Node
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
+
# `pos` is the position of the _end_ of a token
|
7
|
+
attr_reader :pos
|
8
|
+
|
9
|
+
def initialize pos
|
10
|
+
@pos = pos
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return the line of this node given `doc`
|
14
|
+
def line doc
|
15
|
+
doc[0, @pos].count("\n") + 1
|
16
|
+
end
|
17
|
+
|
6
18
|
<%- nodes.each do |node| -%>
|
7
|
-
|
19
|
+
def <%= node.human_name %>?; false; end
|
8
20
|
<%- end -%>
|
9
21
|
def each(&blk)
|
10
22
|
yield self
|
@@ -17,7 +29,8 @@ module TinyGQL
|
|
17
29
|
<%- if node.fields.any? -%>
|
18
30
|
attr_reader <%= node.fields.map { |v| ":" + v.name }.join(", ") %>
|
19
31
|
|
20
|
-
def initialize <%= node.fields.map(&:name).join(", ") %>
|
32
|
+
def initialize <%= (["pos"] + node.fields.map(&:name)).join(", ") %>
|
33
|
+
super(pos)
|
21
34
|
<%- node.fields.each do |field| -%>
|
22
35
|
@<%= field.name %> = <%= field.name %>
|
23
36
|
<%- end -%>
|