Skip to content

Commit b71c906

Browse files
committed
Bug: printer can print non-parsable value
This fixes a bug where an empty "block" list could be skipped by the printer. Commit: ea5b241487c884edb561b12e0a92e947107bbfc1 [ea5b241] Parents: ec05b5404b Author: Lee Byron <[email protected]> Date: 5 May 2016 at 7:26:11 AM SGT Commit Date: 5 May 2016 at 7:26:13 AM SGT
1 parent 2b3b103 commit b71c906

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

language/printer/printer.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ func wrap(start, maybeString, end string) string {
9292
}
9393
return start + maybeString + end
9494
}
95+
96+
// Given array, print each item on its own line, wrapped in an indented "{ }" block.
9597
func block(maybeArray interface{}) string {
96-
if maybeArray == nil {
97-
return ""
98-
}
9998
s := toSliceString(maybeArray)
99+
if len(s) == 0 {
100+
return "{}"
101+
}
100102
return indent("{\n"+join(s, "\n")) + "\n}"
101103
}
102104

language/printer/schema_printer_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ extend type Foo {
9090
seven(argument: [String]): Type
9191
}
9292
93+
type NoFields {}
94+
9395
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
9496
9597
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

schema-kitchen-sink.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ extend type Foo {
3737
seven(argument: [String]): Type
3838
}
3939

40+
type NoFields {}
41+
4042
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
4143

4244
directive @include(if: Boolean!)

0 commit comments

Comments
 (0)