@@ -70,6 +70,22 @@ func getMapValueString(m map[string]interface{}, key string) string {
70
70
}
71
71
return ""
72
72
}
73
+ func getDescription (raw interface {}) string {
74
+ var desc string
75
+
76
+ switch node := raw .(type ) {
77
+ case ast.DescribableNode :
78
+ if sval := node .GetDescription (); sval != nil {
79
+ desc = sval .Value
80
+ }
81
+ case map [string ]interface {}:
82
+ desc = getMapValueString (node , "Description.Value" )
83
+ }
84
+ if desc != "" {
85
+ desc = fmt .Sprintf (`"""%s"""` , desc )
86
+ }
87
+ return desc
88
+ }
73
89
74
90
func toSliceString (slice interface {}) []string {
75
91
if slice == nil {
@@ -506,6 +522,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
506
522
fmt .Sprintf ("%v" , node .Name ),
507
523
join (directives , " " ),
508
524
}, " " )
525
+ if desc := getDescription (node ); desc != "" {
526
+ str = join ([]string {desc , str }, "\n " )
527
+ }
509
528
return visitor .ActionUpdate , str
510
529
case map [string ]interface {}:
511
530
name := getMapValueString (node , "Name" )
@@ -518,6 +537,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
518
537
name ,
519
538
join (directives , " " ),
520
539
}, " " )
540
+ if desc := getDescription (node ); desc != "" {
541
+ str = join ([]string {desc , str }, "\n " )
542
+ }
521
543
return visitor .ActionUpdate , str
522
544
}
523
545
return visitor .ActionNoChange , nil
@@ -539,6 +561,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
539
561
join (directives , " " ),
540
562
block (fields ),
541
563
}, " " )
564
+ if desc := getDescription (node ); desc != "" {
565
+ str = join ([]string {desc , str }, "\n " )
566
+ }
542
567
return visitor .ActionUpdate , str
543
568
case map [string ]interface {}:
544
569
name := getMapValueString (node , "Name" )
@@ -555,6 +580,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
555
580
join (directives , " " ),
556
581
block (fields ),
557
582
}, " " )
583
+ if desc := getDescription (node ); desc != "" {
584
+ str = join ([]string {desc , str }, "\n " )
585
+ }
558
586
return visitor .ActionUpdate , str
559
587
}
560
588
return visitor .ActionNoChange , nil
@@ -570,6 +598,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
570
598
directives = append (directives , fmt .Sprintf ("%v" , directive .Name ))
571
599
}
572
600
str := name + wrap ("(" , join (args , ", " ), ")" ) + ": " + ttype + wrap (" " , join (directives , " " ), "" )
601
+ if desc := getDescription (node ); desc != "" {
602
+ str = join ([]string {desc , str }, "\n " )
603
+ }
573
604
return visitor .ActionUpdate , str
574
605
case map [string ]interface {}:
575
606
name := getMapValueString (node , "Name" )
@@ -580,6 +611,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
580
611
directives = append (directives , fmt .Sprintf ("%v" , directive ))
581
612
}
582
613
str := name + wrap ("(" , join (args , ", " ), ")" ) + ": " + ttype + wrap (" " , join (directives , " " ), "" )
614
+ if desc := getDescription (node ); desc != "" {
615
+ str = join ([]string {desc , str }, "\n " )
616
+ }
583
617
return visitor .ActionUpdate , str
584
618
}
585
619
return visitor .ActionNoChange , nil
@@ -599,7 +633,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
599
633
wrap ("= " , defaultValue , "" ),
600
634
join (directives , " " ),
601
635
}, " " )
602
-
636
+ if desc := getDescription (node ); desc != "" {
637
+ str = join ([]string {desc , str }, " " )
638
+ }
603
639
return visitor .ActionUpdate , str
604
640
case map [string ]interface {}:
605
641
name := getMapValueString (node , "Name" )
@@ -614,6 +650,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
614
650
wrap ("= " , defaultValue , "" ),
615
651
join (directives , " " ),
616
652
}, " " )
653
+ if desc := getDescription (node ); desc != "" {
654
+ str = join ([]string {desc , str }, " " )
655
+ }
617
656
return visitor .ActionUpdate , str
618
657
}
619
658
return visitor .ActionNoChange , nil
@@ -633,6 +672,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
633
672
join (directives , " " ),
634
673
block (fields ),
635
674
}, " " )
675
+ if desc := getDescription (node ); desc != "" {
676
+ str = join ([]string {desc , str }, "\n " )
677
+ }
636
678
return visitor .ActionUpdate , str
637
679
case map [string ]interface {}:
638
680
name := getMapValueString (node , "Name" )
@@ -647,6 +689,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
647
689
join (directives , " " ),
648
690
block (fields ),
649
691
}, " " )
692
+ if desc := getDescription (node ); desc != "" {
693
+ str = join ([]string {desc , str }, "\n " )
694
+ }
650
695
return visitor .ActionUpdate , str
651
696
}
652
697
return visitor .ActionNoChange , nil
@@ -666,6 +711,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
666
711
join (directives , " " ),
667
712
"= " + join (types , " | " ),
668
713
}, " " )
714
+ if desc := getDescription (node ); desc != "" {
715
+ str = join ([]string {desc , str }, "\n " )
716
+ }
669
717
return visitor .ActionUpdate , str
670
718
case map [string ]interface {}:
671
719
name := getMapValueString (node , "Name" )
@@ -680,6 +728,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
680
728
join (directives , " " ),
681
729
"= " + join (types , " | " ),
682
730
}, " " )
731
+ if desc := getDescription (node ); desc != "" {
732
+ str = join ([]string {desc , str }, "\n " )
733
+ }
683
734
return visitor .ActionUpdate , str
684
735
}
685
736
return visitor .ActionNoChange , nil
@@ -699,6 +750,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
699
750
join (directives , " " ),
700
751
block (values ),
701
752
}, " " )
753
+ if desc := getDescription (node ); desc != "" {
754
+ str = join ([]string {desc , str }, "\n " )
755
+ }
702
756
return visitor .ActionUpdate , str
703
757
case map [string ]interface {}:
704
758
name := getMapValueString (node , "Name" )
@@ -713,6 +767,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
713
767
join (directives , " " ),
714
768
block (values ),
715
769
}, " " )
770
+ if desc := getDescription (node ); desc != "" {
771
+ str = join ([]string {desc , str }, "\n " )
772
+ }
716
773
return visitor .ActionUpdate , str
717
774
}
718
775
return visitor .ActionNoChange , nil
@@ -729,6 +786,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
729
786
name ,
730
787
join (directives , " " ),
731
788
}, " " )
789
+ if desc := getDescription (node ); desc != "" {
790
+ str = join ([]string {desc , str }, "\n " )
791
+ }
732
792
return visitor .ActionUpdate , str
733
793
case map [string ]interface {}:
734
794
name := getMapValueString (node , "Name" )
@@ -740,6 +800,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
740
800
name ,
741
801
join (directives , " " ),
742
802
}, " " )
803
+ if desc := getDescription (node ); desc != "" {
804
+ str = join ([]string {desc , str }, "\n " )
805
+ }
743
806
return visitor .ActionUpdate , str
744
807
}
745
808
return visitor .ActionNoChange , nil
@@ -759,6 +822,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
759
822
join (directives , " " ),
760
823
block (fields ),
761
824
}, " " )
825
+ if desc := getDescription (node ); desc != "" {
826
+ str = join ([]string {desc , str }, "\n " )
827
+ }
762
828
return visitor .ActionUpdate , str
763
829
case map [string ]interface {}:
764
830
name := getMapValueString (node , "Name" )
@@ -773,6 +839,9 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
773
839
join (directives , " " ),
774
840
block (fields ),
775
841
}, " " )
842
+ if desc := getDescription (node ); desc != "" {
843
+ str = join ([]string {desc , str }, "\n " )
844
+ }
776
845
return visitor .ActionUpdate , str
777
846
}
778
847
return visitor .ActionNoChange , nil
@@ -782,10 +851,16 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
782
851
case * ast.TypeExtensionDefinition :
783
852
definition := fmt .Sprintf ("%v" , node .Definition )
784
853
str := "extend " + definition
854
+ if desc := getDescription (node ); desc != "" {
855
+ str = join ([]string {desc , str }, "\n " )
856
+ }
785
857
return visitor .ActionUpdate , str
786
858
case map [string ]interface {}:
787
859
definition := getMapValueString (node , "Definition" )
788
860
str := "extend " + definition
861
+ if desc := getDescription (node ); desc != "" {
862
+ str = join ([]string {desc , str }, "\n " )
863
+ }
789
864
return visitor .ActionUpdate , str
790
865
}
791
866
return visitor .ActionNoChange , nil
@@ -795,13 +870,19 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
795
870
case * ast.DirectiveDefinition :
796
871
args := wrap ("(" , join (toSliceString (node .Arguments ), ", " ), ")" )
797
872
str := fmt .Sprintf ("directive @%v%v on %v" , node .Name , args , join (toSliceString (node .Locations ), " | " ))
873
+ if desc := getDescription (node ); desc != "" {
874
+ str = join ([]string {desc , str }, "\n " )
875
+ }
798
876
return visitor .ActionUpdate , str
799
877
case map [string ]interface {}:
800
878
name := getMapValueString (node , "Name" )
801
879
locations := toSliceString (getMapValue (node , "Locations" ))
802
880
args := toSliceString (getMapValue (node , "Arguments" ))
803
881
argsStr := wrap ("(" , join (args , ", " ), ")" )
804
882
str := fmt .Sprintf ("directive @%v%v on %v" , name , argsStr , join (locations , " | " ))
883
+ if desc := getDescription (node ); desc != "" {
884
+ str = join ([]string {desc , str }, "\n " )
885
+ }
805
886
return visitor .ActionUpdate , str
806
887
}
807
888
return visitor .ActionNoChange , nil
0 commit comments