diff --git a/src/language-graphql/printer-graphql.js b/src/language-graphql/printer-graphql.js index 63c2e752..154cb37f 100644 --- a/src/language-graphql/printer-graphql.js +++ b/src/language-graphql/printer-graphql.js @@ -126,9 +126,13 @@ function genericPrint(path, options, print) { } case "StringValue": { if (n.block) { - // It is not possible to distinguish between """\nabc\n""" and """abc""" - // https://github.com/graphql/graphql-js/issues/1188 - return options.originalText.slice(util.locStart(n), util.locEnd(n)); + return concat([ + '"""', + hardline, + join(hardline, n.value.replace(/"""/g, "\\$&").split("\n")), + hardline, + '"""' + ]); } return concat(['"', n.value.replace(/["\\]/g, "\\$&"), '"']); } @@ -274,6 +278,8 @@ function genericPrint(path, options, print) { case "FieldDefinition": { return concat([ + path.call(print, "description"), + n.description ? hardline : "", path.call(print, "name"), n.arguments.length > 0 ? group( diff --git a/tests/graphql_kitchen_sink/__snapshots__/jsfmt.spec.js.snap b/tests/graphql_kitchen_sink/__snapshots__/jsfmt.spec.js.snap index f5683909..72d49926 100644 --- a/tests/graphql_kitchen_sink/__snapshots__/jsfmt.spec.js.snap +++ b/tests/graphql_kitchen_sink/__snapshots__/jsfmt.spec.js.snap @@ -110,9 +110,12 @@ fragment frag on Friend { foo( size: $size bar: $b - obj: { key: "value", block: """ + obj: { + key: "value" + block: """ block string uses \\""" - """ } + """ + } ) } diff --git a/tests/graphql_string/__snapshots__/jsfmt.spec.js.snap b/tests/graphql_string/__snapshots__/jsfmt.spec.js.snap index 72c3b20e..5636e278 100644 --- a/tests/graphql_string/__snapshots__/jsfmt.spec.js.snap +++ b/tests/graphql_string/__snapshots__/jsfmt.spec.js.snap @@ -14,12 +14,29 @@ abc type T { a: Int } + +""" + a + b + c + """ +type T { a: Int } + +type Foo { +""" +This is a description +of the \`one\` field. +""" + one: Type +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ query X($a: Int) @relay(meta: "{\\"lowPri\\": true}") { a } -"""abc""" +""" +abc +""" type T { a: Int } @@ -31,4 +48,21 @@ type T { a: Int } +""" +a + b + c +""" +type T { + a: Int +} + +type Foo { + """ + This is a description + of the \`one\` field. + """ + one: Type +} + `; diff --git a/tests/graphql_string/string.graphql b/tests/graphql_string/string.graphql index 6f1d2019..3a174cfb 100644 --- a/tests/graphql_string/string.graphql +++ b/tests/graphql_string/string.graphql @@ -11,3 +11,18 @@ abc type T { a: Int } + +""" + a + b + c + """ +type T { a: Int } + +type Foo { +""" +This is a description +of the `one` field. +""" + one: Type +}