Skip to content

Commit ea5b241

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.
1 parent ec05b54 commit ea5b241

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/language/__tests__/schema-kitchen-sink.graphql

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

45+
type NoFields {}
46+
4547
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
4648

4749
directive @include(if: Boolean!)

src/language/__tests__/schema-printer-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ extend type Foo {
8888
seven(argument: [String]): Type
8989
}
9090
91+
type NoFields {}
92+
9193
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
9294
9395
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

src/language/printer.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ function join(maybeArray, separator) {
144144
}
145145

146146
/**
147-
* Given maybeArray, print an empty string if it is null or empty, otherwise
148-
* print each item on its own line, wrapped in an indented "{ }" block.
147+
* Given array, print each item on its own line, wrapped in an
148+
* indented "{ }" block.
149149
*/
150-
function block(maybeArray) {
151-
return length(maybeArray) ?
152-
indent('{\n' + join(maybeArray, '\n')) + '\n}' :
153-
'';
150+
function block(array) {
151+
return array && array.length !== 0 ?
152+
indent('{\n' + join(array, '\n')) + '\n}' :
153+
'{}';
154154
}
155155

156156
/**
@@ -166,7 +166,3 @@ function wrap(start, maybeString, end) {
166166
function indent(maybeString) {
167167
return maybeString && maybeString.replace(/\n/g, '\n ');
168168
}
169-
170-
function length(maybeArray) {
171-
return maybeArray ? maybeArray.length : 0;
172-
}

0 commit comments

Comments
 (0)