Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix description formatting (possible " character) #289

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Cat0 comment
# Cat0 comment 2
"""Cat0 description"""
"""
Cat0 description
"""
scalar Cat0
# Cat1 comment
type Cat1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
28 changes: 21 additions & 7 deletions formatter/testdata/baseline/FormatSchema/comments/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Cat0 description"""
"""
Cat0 description
"""
scalar Cat0
type Cat1 {
name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
28 changes: 21 additions & 7 deletions formatter/testdata/baseline/FormatSchema/default/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Cat0 description"""
"""
Cat0 description
"""
scalar Cat0
type Cat1 {
name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Cat0 comment
# Cat0 comment 2
"""Cat0 description"""
"""
Cat0 description
"""
scalar Cat0
# Cat1 comment
type Cat1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# before schema description comment
"""schema description"""
"""
schema description
"""
# after schema description comment
schema {
# before query comment
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Cat0 description"""
"""
Cat0 description
"""
scalar Cat0
type Cat1 {
name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading
Loading