Skip to content

Commit df5ad25

Browse files
committed
go back to master, lets do additive not editing
1 parent d9c034d commit df5ad25

File tree

3 files changed

+3
-115
lines changed

3 files changed

+3
-115
lines changed

language/printer/printer.go

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,6 @@ func getMapValueString(m map[string]interface{}, key string) string {
7070
}
7171
return ""
7272
}
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-
if strings.ContainsRune(desc, '\n') {
86-
87-
}
88-
desc = fmt.Sprintf(`"""%s"""`, desc)
89-
}
90-
return desc
91-
}
9273

9374
func toSliceString(slice interface{}) []string {
9475
if slice == nil {
@@ -525,9 +506,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
525506
fmt.Sprintf("%v", node.Name),
526507
join(directives, " "),
527508
}, " ")
528-
if desc := getDescription(node); desc != "" {
529-
str = join([]string{desc, str}, "\n")
530-
}
531509
return visitor.ActionUpdate, str
532510
case map[string]interface{}:
533511
name := getMapValueString(node, "Name")
@@ -540,9 +518,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
540518
name,
541519
join(directives, " "),
542520
}, " ")
543-
if desc := getDescription(node); desc != "" {
544-
str = join([]string{desc, str}, "\n")
545-
}
546521
return visitor.ActionUpdate, str
547522
}
548523
return visitor.ActionNoChange, nil
@@ -564,9 +539,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
564539
join(directives, " "),
565540
block(fields),
566541
}, " ")
567-
if desc := getDescription(node); desc != "" {
568-
str = join([]string{desc, str}, "\n")
569-
}
570542
return visitor.ActionUpdate, str
571543
case map[string]interface{}:
572544
name := getMapValueString(node, "Name")
@@ -583,9 +555,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
583555
join(directives, " "),
584556
block(fields),
585557
}, " ")
586-
if desc := getDescription(node); desc != "" {
587-
str = join([]string{desc, str}, "\n")
588-
}
589558
return visitor.ActionUpdate, str
590559
}
591560
return visitor.ActionNoChange, nil
@@ -601,9 +570,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
601570
directives = append(directives, fmt.Sprintf("%v", directive.Name))
602571
}
603572
str := name + wrap("(", join(args, ", "), ")") + ": " + ttype + wrap(" ", join(directives, " "), "")
604-
if desc := getDescription(node); desc != "" {
605-
str = join([]string{desc, str}, "\n")
606-
}
607573
return visitor.ActionUpdate, str
608574
case map[string]interface{}:
609575
name := getMapValueString(node, "Name")
@@ -614,9 +580,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
614580
directives = append(directives, fmt.Sprintf("%v", directive))
615581
}
616582
str := name + wrap("(", join(args, ", "), ")") + ": " + ttype + wrap(" ", join(directives, " "), "")
617-
if desc := getDescription(node); desc != "" {
618-
str = join([]string{desc, str}, "\n")
619-
}
620583
return visitor.ActionUpdate, str
621584
}
622585
return visitor.ActionNoChange, nil
@@ -636,9 +599,7 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
636599
wrap("= ", defaultValue, ""),
637600
join(directives, " "),
638601
}, " ")
639-
if desc := getDescription(node); desc != "" {
640-
str = join([]string{desc, str}, " ")
641-
}
602+
642603
return visitor.ActionUpdate, str
643604
case map[string]interface{}:
644605
name := getMapValueString(node, "Name")
@@ -653,9 +614,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
653614
wrap("= ", defaultValue, ""),
654615
join(directives, " "),
655616
}, " ")
656-
if desc := getDescription(node); desc != "" {
657-
str = join([]string{desc, str}, " ")
658-
}
659617
return visitor.ActionUpdate, str
660618
}
661619
return visitor.ActionNoChange, nil
@@ -675,9 +633,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
675633
join(directives, " "),
676634
block(fields),
677635
}, " ")
678-
if desc := getDescription(node); desc != "" {
679-
str = join([]string{desc, str}, "\n")
680-
}
681636
return visitor.ActionUpdate, str
682637
case map[string]interface{}:
683638
name := getMapValueString(node, "Name")
@@ -692,9 +647,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
692647
join(directives, " "),
693648
block(fields),
694649
}, " ")
695-
if desc := getDescription(node); desc != "" {
696-
str = join([]string{desc, str}, "\n")
697-
}
698650
return visitor.ActionUpdate, str
699651
}
700652
return visitor.ActionNoChange, nil
@@ -714,9 +666,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
714666
join(directives, " "),
715667
"= " + join(types, " | "),
716668
}, " ")
717-
if desc := getDescription(node); desc != "" {
718-
str = join([]string{desc, str}, "\n")
719-
}
720669
return visitor.ActionUpdate, str
721670
case map[string]interface{}:
722671
name := getMapValueString(node, "Name")
@@ -731,9 +680,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
731680
join(directives, " "),
732681
"= " + join(types, " | "),
733682
}, " ")
734-
if desc := getDescription(node); desc != "" {
735-
str = join([]string{desc, str}, "\n")
736-
}
737683
return visitor.ActionUpdate, str
738684
}
739685
return visitor.ActionNoChange, nil
@@ -753,9 +699,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
753699
join(directives, " "),
754700
block(values),
755701
}, " ")
756-
if desc := getDescription(node); desc != "" {
757-
str = join([]string{desc, str}, "\n")
758-
}
759702
return visitor.ActionUpdate, str
760703
case map[string]interface{}:
761704
name := getMapValueString(node, "Name")
@@ -770,9 +713,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
770713
join(directives, " "),
771714
block(values),
772715
}, " ")
773-
if desc := getDescription(node); desc != "" {
774-
str = join([]string{desc, str}, "\n")
775-
}
776716
return visitor.ActionUpdate, str
777717
}
778718
return visitor.ActionNoChange, nil
@@ -789,9 +729,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
789729
name,
790730
join(directives, " "),
791731
}, " ")
792-
if desc := getDescription(node); desc != "" {
793-
str = join([]string{desc, str}, "\n")
794-
}
795732
return visitor.ActionUpdate, str
796733
case map[string]interface{}:
797734
name := getMapValueString(node, "Name")
@@ -803,9 +740,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
803740
name,
804741
join(directives, " "),
805742
}, " ")
806-
if desc := getDescription(node); desc != "" {
807-
str = join([]string{desc, str}, "\n")
808-
}
809743
return visitor.ActionUpdate, str
810744
}
811745
return visitor.ActionNoChange, nil
@@ -825,9 +759,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
825759
join(directives, " "),
826760
block(fields),
827761
}, " ")
828-
if desc := getDescription(node); desc != "" {
829-
str = join([]string{desc, str}, "\n")
830-
}
831762
return visitor.ActionUpdate, str
832763
case map[string]interface{}:
833764
name := getMapValueString(node, "Name")
@@ -842,9 +773,6 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
842773
join(directives, " "),
843774
block(fields),
844775
}, " ")
845-
if desc := getDescription(node); desc != "" {
846-
str = join([]string{desc, str}, "\n")
847-
}
848776
return visitor.ActionUpdate, str
849777
}
850778
return visitor.ActionNoChange, nil
@@ -854,16 +782,10 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
854782
case *ast.TypeExtensionDefinition:
855783
definition := fmt.Sprintf("%v", node.Definition)
856784
str := "extend " + definition
857-
if desc := getDescription(node); desc != "" {
858-
str = join([]string{desc, str}, "\n")
859-
}
860785
return visitor.ActionUpdate, str
861786
case map[string]interface{}:
862787
definition := getMapValueString(node, "Definition")
863788
str := "extend " + definition
864-
if desc := getDescription(node); desc != "" {
865-
str = join([]string{desc, str}, "\n")
866-
}
867789
return visitor.ActionUpdate, str
868790
}
869791
return visitor.ActionNoChange, nil
@@ -873,19 +795,13 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
873795
case *ast.DirectiveDefinition:
874796
args := wrap("(", join(toSliceString(node.Arguments), ", "), ")")
875797
str := fmt.Sprintf("directive @%v%v on %v", node.Name, args, join(toSliceString(node.Locations), " | "))
876-
if desc := getDescription(node); desc != "" {
877-
str = join([]string{desc, str}, "\n")
878-
}
879798
return visitor.ActionUpdate, str
880799
case map[string]interface{}:
881800
name := getMapValueString(node, "Name")
882801
locations := toSliceString(getMapValue(node, "Locations"))
883802
args := toSliceString(getMapValue(node, "Arguments"))
884803
argsStr := wrap("(", join(args, ", "), ")")
885804
str := fmt.Sprintf("directive @%v%v on %v", name, argsStr, join(locations, " | "))
886-
if desc := getDescription(node); desc != "" {
887-
str = join([]string{desc, str}, "\n")
888-
}
889805
return visitor.ActionUpdate, str
890806
}
891807
return visitor.ActionNoChange, nil

language/printer/schema_printer_test.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ func TestSchemaPrinter_PrintsKitchenSink(t *testing.T) {
5858
mutation: MutationType
5959
}
6060
61-
"""object description"""
6261
type Foo implements Bar & Baz {
63-
"""one field description"""
6462
one: Type
6563
two(argument: InputType!): Type
66-
three(argument: InputType, """arg description""" other: String): Int
67-
"""four field description"""
64+
three(argument: InputType, other: String): Int
6865
four(argument: String = "string"): String
6966
five(argument: [String] = ["string", "string"]): String
7067
six(argument: InputType = {key: "value"}): Type
@@ -74,9 +71,6 @@ type AnnotatedObject @onObject(arg: "value") {
7471
annotatedField(arg: Type = "default" @onArg): Type @onField
7572
}
7673
77-
"""interface description
78-
79-
multiple lines"""
8074
interface Bar {
8175
one: Type
8276
four(argument: String = "string"): String
@@ -88,18 +82,14 @@ interface AnnotatedInterface @onInterface {
8882
8983
union Feed = Story | Article | Advert
9084
91-
"""union description"""
9285
union AnnotatedUnion @onUnion = A | B
9386
94-
"""scalar description"""
9587
scalar CustomScalar
9688
9789
scalar AnnotatedScalar @onScalar
9890
99-
"""enum description"""
10091
enum Site {
10192
DESKTOP
102-
"""enum member description"""
10393
MOBILE
10494
}
10595
@@ -108,10 +98,8 @@ enum AnnotatedEnum @onEnum {
10898
OTHER_VALUE
10999
}
110100
111-
"""input description"""
112101
input InputType {
113102
key: String!
114-
"""input value description"""
115103
answer: Int = 42
116104
}
117105
@@ -127,7 +115,6 @@ extend type Foo @onType {}
127115
128116
type NoFields {}
129117
130-
"""directive description"""
131118
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
132119
133120
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

schema-kitchen-sink.graphql

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@ schema {
55
mutation: MutationType
66
}
77

8-
"""
9-
object description
10-
"""
118
type Foo implements Bar & Baz {
12-
"""one field description"""
139
one: Type
1410
two(argument: InputType!): Type
15-
three(argument: InputType, """arg description""" other: String): Int
16-
"""four field description"""
11+
three(argument: InputType, other: String): Int
1712
four(argument: String = "string"): String
1813
five(argument: [String] = ["string", "string"]): String
1914
six(argument: InputType = {key: "value"}): Type
@@ -23,9 +18,6 @@ type AnnotatedObject @onObject(arg: "value") {
2318
annotatedField(arg: Type = "default" @onArg): Type @onField
2419
}
2520

26-
"""interface description
27-
28-
multiple lines"""
2921
interface Bar {
3022
one: Type
3123
four(argument: String = "string"): String
@@ -37,18 +29,14 @@ interface AnnotatedInterface @onInterface {
3729

3830
union Feed = Story | Article | Advert
3931

40-
"""union description"""
4132
union AnnotatedUnion @onUnion = A | B
4233

43-
"""scalar description"""
4434
scalar CustomScalar
4535

4636
scalar AnnotatedScalar @onScalar
4737

48-
"""enum description"""
4938
enum Site {
5039
DESKTOP
51-
"""enum member description"""
5240
MOBILE
5341
}
5442

@@ -57,10 +45,8 @@ enum AnnotatedEnum @onEnum {
5745
OTHER_VALUE
5846
}
5947

60-
"""input description"""
6148
input InputType {
6249
key: String!
63-
"""input value description"""
6450
answer: Int = 42
6551
}
6652

@@ -76,7 +62,6 @@ extend type Foo @onType {}
7662

7763
type NoFields {}
7864

79-
"""directive description"""
8065
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
8166

8267
directive @include(if: Boolean!)

0 commit comments

Comments
 (0)