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

improve formatting of argument lists descriptions #124

Merged
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
10 changes: 9 additions & 1 deletion formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ func (f *formatter) FormatArgumentDefinitionList(lists ast.ArgumentDefinitionLis
}

func (f *formatter) FormatArgumentDefinition(def *ast.ArgumentDefinition) {
f.WriteDescription(def.Description)
if def.Description != "" {
f.WriteNewline().IncrementIndent()
f.WriteDescription(def.Description)
}

f.WriteWord(def.Name).NoPadding().WriteString(":").NeedPadding()
f.FormatType(def.Type)
Expand All @@ -297,6 +300,11 @@ func (f *formatter) FormatArgumentDefinition(def *ast.ArgumentDefinition) {
f.WriteWord("=")
f.FormatValue(def.DefaultValue)
}

if def.Description != "" {
f.DecrementIndent()
f.WriteNewline()
}
}

func (f *formatter) FormatDirectiveLocation(location ast.DirectiveLocation) {
Expand Down
36 changes: 36 additions & 0 deletions formatter/testdata/baseline/FormatSchema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,46 @@ schema {
}
type TopMutation {
noop: Boolean
noop2(
"""
noop2 foo bar
"""
arg: String
): Boolean
noop3(
"""
noop3 foo bar
"""
arg: String
): Boolean
}
type TopQuery {
noop: Boolean
noop2(
"""
noop2 foo bar
"""
arg: String
): Boolean
noop3(
"""
noop3 foo bar
"""
arg: String
): Boolean
}
type TopSubscription {
noop: Boolean
noop2(
"""
noop2 foo bar
"""
arg: String
): Boolean
noop3(
"""
noop3 foo bar
"""
arg: String
): Boolean
}
40 changes: 38 additions & 2 deletions formatter/testdata/baseline/FormatSchemaDocument/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,48 @@ schema {
mutation: TopMutation
subscription: TopSubscription
}
type TopQuery {
type TopMutation {
noop: Boolean
noop2(
"""
noop2 foo bar
"""
arg: String
): Boolean
noop3(
"""
noop3 foo bar
"""
arg: String
): Boolean
}
type TopMutation {
type TopQuery {
noop: Boolean
noop2(
"""
noop2 foo bar
"""
arg: String
): Boolean
noop3(
"""
noop3 foo bar
"""
arg: String
): Boolean
}
type TopSubscription {
noop: Boolean
noop2(
"""
noop2 foo bar
"""
arg: String
): Boolean
noop3(
"""
noop3 foo bar
"""
arg: String
): Boolean
}
45 changes: 38 additions & 7 deletions formatter/testdata/source/schema/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
schema {
query: TopQuery
mutation: TopMutation
subscription: TopSubscription
query: TopQuery
mutation: TopMutation
subscription: TopSubscription
}

type TopQuery {
type TopMutation {
noop: Boolean
noop2("""
noop2 foo bar
"""
arg: String
): Boolean
noop3("noop3 foo bar"
arg: String
): Boolean
}

type TopMutation {
noop: Boolean
type TopQuery {
noop: Boolean

noop2("""
noop2 foo bar
"""
arg: String
): Boolean

noop3(
"noop3 foo bar"
arg: String
): Boolean
}

type TopSubscription {
noop: Boolean
noop: Boolean

noop2(
"""
noop2 foo bar
"""
arg: String
): Boolean

noop3(
"noop3 foo bar"
arg: String
): Boolean
}