Skip to content

Commit

Permalink
Bug: printer can print non-parsable value
Browse files Browse the repository at this point in the history
This fixes a bug where an empty "block" list could be skipped by the printer.
  • Loading branch information
leebyron committed May 4, 2016
1 parent ec05b54 commit ea5b241
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/language/__tests__/schema-kitchen-sink.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extend type Foo {
seven(argument: [String]): Type
}

type NoFields {}

directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

directive @include(if: Boolean!)
Expand Down
2 changes: 2 additions & 0 deletions src/language/__tests__/schema-printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ extend type Foo {
seven(argument: [String]): Type
}
type NoFields {}
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
Expand Down
16 changes: 6 additions & 10 deletions src/language/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ function join(maybeArray, separator) {
}

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

/**
Expand All @@ -166,7 +166,3 @@ function wrap(start, maybeString, end) {
function indent(maybeString) {
return maybeString && maybeString.replace(/\n/g, '\n ');
}

function length(maybeArray) {
return maybeArray ? maybeArray.length : 0;
}

0 comments on commit ea5b241

Please sign in to comment.