diff --git a/src/language-graphql/printer-graphql.js b/src/language-graphql/printer-graphql.js index ed6d61bd7..265597be4 100644 --- a/src/language-graphql/printer-graphql.js +++ b/src/language-graphql/printer-graphql.js @@ -24,10 +24,22 @@ function genericPrint(path, options, print) { switch (n.kind) { case "Document": { - return concat([ - join(concat([hardline, hardline]), path.map(print, "definitions")), - hardline - ]); + const parts = []; + path.map((pathChild, index) => { + parts.push(concat([pathChild.call(print)])); + parts.push(hardline); + if ( + index !== n.definitions.length - 1 && + sharedUtil.isNextLineEmpty( + options.originalText, + pathChild.getValue(), + options + ) + ) { + parts.push(hardline); + } + }, "definitions"); + return concat(parts, hardline); } case "OperationDefinition": { const hasOperation = options.originalText[options.locStart(n)] !== "{"; diff --git a/tests/graphql_directive_decl/__snapshots__/jsfmt.spec.js.snap b/tests/graphql_directive_decl/__snapshots__/jsfmt.spec.js.snap index 5db608cf3..3e940d90f 100644 --- a/tests/graphql_directive_decl/__snapshots__/jsfmt.spec.js.snap +++ b/tests/graphql_directive_decl/__snapshots__/jsfmt.spec.js.snap @@ -7,17 +7,28 @@ directive @a(as: String = 1) on QUERY directive @a(as: String, b: Int!) on QUERY directive @a(as: String! = 1 @deprecated) on QUERY directive @a(as: String! = 1 @deprecated) on QUERY | MUTATION + +directive @a on QUERY + + +directive @a(as: String) on QUERY + + + + +directive @a(as: String = 1) on QUERY ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +directive @a on QUERY +directive @a(as: String) on QUERY +directive @a(as: String = 1) on QUERY +directive @a(as: String, b: Int!) on QUERY +directive @a(as: String! = 1 @deprecated) on QUERY +directive @a(as: String! = 1 @deprecated) on QUERY | MUTATION + directive @a on QUERY directive @a(as: String) on QUERY directive @a(as: String = 1) on QUERY -directive @a(as: String, b: Int!) on QUERY - -directive @a(as: String! = 1 @deprecated) on QUERY - -directive @a(as: String! = 1 @deprecated) on QUERY | MUTATION - `; diff --git a/tests/graphql_directive_decl/directive_decl.graphql b/tests/graphql_directive_decl/directive_decl.graphql index 4f60a34ab..531c6112f 100644 --- a/tests/graphql_directive_decl/directive_decl.graphql +++ b/tests/graphql_directive_decl/directive_decl.graphql @@ -4,3 +4,13 @@ directive @a(as: String = 1) on QUERY directive @a(as: String, b: Int!) on QUERY directive @a(as: String! = 1 @deprecated) on QUERY directive @a(as: String! = 1 @deprecated) on QUERY | MUTATION + +directive @a on QUERY + + +directive @a(as: String) on QUERY + + + + +directive @a(as: String = 1) on QUERY