From 8ca0cc933ca2cfed33dfc987dd458d9370eaed89 Mon Sep 17 00:00:00 2001 From: Hemanth Bollamreddi Date: Mon, 8 Jan 2024 20:21:18 +0530 Subject: [PATCH] Fix description --- formatter/formatter.go | 11 +++---- .../FormatSchema/comments/definition.graphql | 4 ++- .../FormatSchema/comments/description.graphql | 8 ++++- .../FormatSchema/comments/schema.graphql | 28 ++++++++++++---- .../FormatSchema/default/definition.graphql | 4 ++- .../FormatSchema/default/description.graphql | 8 ++++- .../FormatSchema/default/schema.graphql | 28 ++++++++++++---- .../spaceIndent/definition.graphql | 4 ++- .../spaceIndent/description.graphql | 8 ++++- .../FormatSchema/spaceIndent/schema.graphql | 28 ++++++++++++---- .../comments/definition.graphql | 4 ++- .../comments/description.graphql | 8 ++++- .../comments/schema.graphql | 32 ++++++++++++++----- .../default/definition.graphql | 4 ++- .../default/description.graphql | 8 ++++- .../default/schema.graphql | 32 ++++++++++++++----- .../spaceIndent/definition.graphql | 4 ++- .../spaceIndent/description.graphql | 8 ++++- .../spaceIndent/schema.graphql | 32 ++++++++++++++----- .../source/schema/description.graphql | 17 ++++++---- 20 files changed, 210 insertions(+), 70 deletions(-) diff --git a/formatter/formatter.go b/formatter/formatter.go index 4a0eb5a2..b04af078 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -110,13 +110,10 @@ func (f *formatter) WriteDescription(s string) *formatter { } f.WriteString(`"""`) - if ss := strings.Split(s, "\n"); len(ss) > 1 { - f.WriteNewline() - for _, s := range ss { - f.WriteString(s).WriteNewline() - } - } else { - f.WriteString(s) + ss := strings.Split(s, "\n") + f.WriteNewline() + for _, s := range ss { + f.WriteString(s).WriteNewline() } f.WriteString(`"""`).WriteNewline() diff --git a/formatter/testdata/baseline/FormatSchema/comments/definition.graphql b/formatter/testdata/baseline/FormatSchema/comments/definition.graphql index 420b6255..826b95e6 100644 --- a/formatter/testdata/baseline/FormatSchema/comments/definition.graphql +++ b/formatter/testdata/baseline/FormatSchema/comments/definition.graphql @@ -1,6 +1,8 @@ # Cat0 comment # Cat0 comment 2 -"""Cat0 description""" +""" +Cat0 description +""" scalar Cat0 # Cat1 comment type Cat1 { diff --git a/formatter/testdata/baseline/FormatSchema/comments/description.graphql b/formatter/testdata/baseline/FormatSchema/comments/description.graphql index f03c67cd..0c1b9027 100644 --- a/formatter/testdata/baseline/FormatSchema/comments/description.graphql +++ b/formatter/testdata/baseline/FormatSchema/comments/description.graphql @@ -6,7 +6,13 @@ meow! # type comment type Cat { # field description comment - """Shiny brillian name.""" + """ + Shiny brillian name. + """ # field comment name: String + """ + Only "meow" is allowed. + """ + speaks: String } diff --git a/formatter/testdata/baseline/FormatSchema/comments/schema.graphql b/formatter/testdata/baseline/FormatSchema/comments/schema.graphql index 1f6578be..5081dc1b 100644 --- a/formatter/testdata/baseline/FormatSchema/comments/schema.graphql +++ b/formatter/testdata/baseline/FormatSchema/comments/schema.graphql @@ -6,36 +6,50 @@ schema { type TopMutation { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopQuery { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopSubscription { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg1: String - """noop3 foo bar""" + """ + noop3 foo bar + """ arg2: String ): Boolean } diff --git a/formatter/testdata/baseline/FormatSchema/default/definition.graphql b/formatter/testdata/baseline/FormatSchema/default/definition.graphql index 4ef2b4c9..aa9ecce9 100644 --- a/formatter/testdata/baseline/FormatSchema/default/definition.graphql +++ b/formatter/testdata/baseline/FormatSchema/default/definition.graphql @@ -1,4 +1,6 @@ -"""Cat0 description""" +""" +Cat0 description +""" scalar Cat0 type Cat1 { name: String diff --git a/formatter/testdata/baseline/FormatSchema/default/description.graphql b/formatter/testdata/baseline/FormatSchema/default/description.graphql index a4dca23f..15b68667 100644 --- a/formatter/testdata/baseline/FormatSchema/default/description.graphql +++ b/formatter/testdata/baseline/FormatSchema/default/description.graphql @@ -3,6 +3,12 @@ Cat is best kawaii animal in the world. meow! """ type Cat { - """Shiny brillian name.""" + """ + Shiny brillian name. + """ name: String + """ + Only "meow" is allowed. + """ + speaks: String } diff --git a/formatter/testdata/baseline/FormatSchema/default/schema.graphql b/formatter/testdata/baseline/FormatSchema/default/schema.graphql index 1f6578be..5081dc1b 100644 --- a/formatter/testdata/baseline/FormatSchema/default/schema.graphql +++ b/formatter/testdata/baseline/FormatSchema/default/schema.graphql @@ -6,36 +6,50 @@ schema { type TopMutation { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopQuery { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopSubscription { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg1: String - """noop3 foo bar""" + """ + noop3 foo bar + """ arg2: String ): Boolean } diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/definition.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/definition.graphql index 3ae0afb4..29ced024 100644 --- a/formatter/testdata/baseline/FormatSchema/spaceIndent/definition.graphql +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/definition.graphql @@ -1,4 +1,6 @@ -"""Cat0 description""" +""" +Cat0 description +""" scalar Cat0 type Cat1 { name: String diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/description.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/description.graphql index c92a66cb..3895a3e1 100644 --- a/formatter/testdata/baseline/FormatSchema/spaceIndent/description.graphql +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/description.graphql @@ -3,6 +3,12 @@ Cat is best kawaii animal in the world. meow! """ type Cat { - """Shiny brillian name.""" + """ + Shiny brillian name. + """ name: String + """ + Only "meow" is allowed. + """ + speaks: String } diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/schema.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/schema.graphql index 672b4c81..3811097a 100644 --- a/formatter/testdata/baseline/FormatSchema/spaceIndent/schema.graphql +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/schema.graphql @@ -6,36 +6,50 @@ schema { type TopMutation { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopQuery { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopSubscription { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg1: String - """noop3 foo bar""" + """ + noop3 foo bar + """ arg2: String ): Boolean } diff --git a/formatter/testdata/baseline/FormatSchemaDocument/comments/definition.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/definition.graphql index 1313596b..307aa3f2 100644 --- a/formatter/testdata/baseline/FormatSchemaDocument/comments/definition.graphql +++ b/formatter/testdata/baseline/FormatSchemaDocument/comments/definition.graphql @@ -1,6 +1,8 @@ # Cat0 comment # Cat0 comment 2 -"""Cat0 description""" +""" +Cat0 description +""" scalar Cat0 # Cat1 comment type Cat1 { diff --git a/formatter/testdata/baseline/FormatSchemaDocument/comments/description.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/description.graphql index 61d43e14..18255d27 100644 --- a/formatter/testdata/baseline/FormatSchemaDocument/comments/description.graphql +++ b/formatter/testdata/baseline/FormatSchemaDocument/comments/description.graphql @@ -6,9 +6,15 @@ meow! # type comment type Cat { # field description comment - """Shiny brillian name.""" + """ + Shiny brillian name. + """ # field comment name: String + """ + Only "meow" is allowed. + """ + speaks: String } # end of file comment # end of file comment 2 diff --git a/formatter/testdata/baseline/FormatSchemaDocument/comments/schema.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/schema.graphql index 253c723f..f8b0943a 100644 --- a/formatter/testdata/baseline/FormatSchemaDocument/comments/schema.graphql +++ b/formatter/testdata/baseline/FormatSchemaDocument/comments/schema.graphql @@ -1,5 +1,7 @@ # before schema description comment -"""schema description""" +""" +schema description +""" # after schema description comment schema { # before query comment @@ -13,36 +15,50 @@ schema { type TopMutation { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopQuery { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopSubscription { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg1: String - """noop3 foo bar""" + """ + noop3 foo bar + """ arg2: String ): Boolean } diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/definition.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/definition.graphql index 8e221d9c..0dbcff7d 100644 --- a/formatter/testdata/baseline/FormatSchemaDocument/default/definition.graphql +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/definition.graphql @@ -1,4 +1,6 @@ -"""Cat0 description""" +""" +Cat0 description +""" scalar Cat0 type Cat1 { name: String diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/description.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/description.graphql index a4dca23f..15b68667 100644 --- a/formatter/testdata/baseline/FormatSchemaDocument/default/description.graphql +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/description.graphql @@ -3,6 +3,12 @@ Cat is best kawaii animal in the world. meow! """ type Cat { - """Shiny brillian name.""" + """ + Shiny brillian name. + """ name: String + """ + Only "meow" is allowed. + """ + speaks: String } diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/schema.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/schema.graphql index a23db802..dd7e7949 100644 --- a/formatter/testdata/baseline/FormatSchemaDocument/default/schema.graphql +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/schema.graphql @@ -1,4 +1,6 @@ -"""schema description""" +""" +schema description +""" schema { query: TopQuery mutation: TopMutation @@ -7,36 +9,50 @@ schema { type TopMutation { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopQuery { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopSubscription { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg1: String - """noop3 foo bar""" + """ + noop3 foo bar + """ arg2: String ): Boolean } diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/definition.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/definition.graphql index 3dbb9400..5e4a7c3d 100644 --- a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/definition.graphql +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/definition.graphql @@ -1,4 +1,6 @@ -"""Cat0 description""" +""" +Cat0 description +""" scalar Cat0 type Cat1 { name: String diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/description.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/description.graphql index c92a66cb..3895a3e1 100644 --- a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/description.graphql +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/description.graphql @@ -3,6 +3,12 @@ Cat is best kawaii animal in the world. meow! """ type Cat { - """Shiny brillian name.""" + """ + Shiny brillian name. + """ name: String + """ + Only "meow" is allowed. + """ + speaks: String } diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/schema.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/schema.graphql index f4db1698..0d7511de 100644 --- a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/schema.graphql +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/schema.graphql @@ -1,4 +1,6 @@ -"""schema description""" +""" +schema description +""" schema { query: TopQuery mutation: TopMutation @@ -7,36 +9,50 @@ schema { type TopMutation { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopQuery { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg: String ): Boolean } type TopSubscription { noop: Boolean noop2( - """noop2 foo bar""" + """ + noop2 foo bar + """ arg: String ): Boolean noop3( - """noop3 foo bar""" + """ + noop3 foo bar + """ arg1: String - """noop3 foo bar""" + """ + noop3 foo bar + """ arg2: String ): Boolean } diff --git a/formatter/testdata/source/schema/description.graphql b/formatter/testdata/source/schema/description.graphql index 5e618752..82da7fbc 100644 --- a/formatter/testdata/source/schema/description.graphql +++ b/formatter/testdata/source/schema/description.graphql @@ -2,13 +2,18 @@ """ Cat is best kawaii animal in the world. meow! -""" -# type comment +""" # type comment type Cat { - # field description comment - """Shiny brillian name.""" - # field comment - name: String + # field description comment + """ + Shiny brillian name. + """ + # field comment + name: String + """ + Only "meow" is allowed. + """ + speaks: String } # end of file comment # end of file comment 2