Multi-line field descriptions printing newline #4009
Replies: 2 comments
-
|
Yeah this changed in v16 when description handling switched to using block-string serialization only when the content naturally fits. The workaround is to avoid the leading whitespace in your template literal — graphql-js trims consistent leading whitespace from each line, so if you indent the whole block the trim logic can't kick in. A tagged dedent helper (or |
Beta Was this translation helpful? Give feedback.
-
|
This usually comes from the distinction between a GraphQL description block and the string value stored in the AST. If you write: \"\"\"
Line one
Line two
\"\"\"
type Example {
field: String
}the parser stores a normalized string description. When you print the schema again, the printer decides how to render that string back into SDL. It is not a byte-for-byte preservation of the original source formatting. If you need stable formatting, I would normalize descriptions before building/printing the schema: import { stripIndent } from 'common-tags'
description: stripIndent`
Line one
Line two
`The key is to avoid accidental leading indentation in the actual string value. Once that indentation is part of the description string, the printer has to preserve it as content. So I would treat printed SDL as canonical output, not as a formatter that preserves the original description layout. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Following this
type-graphqldiscussion, sincegraphql-jsv16.0.0, multi-line field descriptions do not seem to be printed correctly.Previously we were able to define them like this:
Now to get the proper printed schema, we need to put the
\nourselves on the description:I think something changed on the
printSchemautility function.Beta Was this translation helpful? Give feedback.
All reactions