6

I am trying to document my APIs using GraphQL. For readability issues, I want to leave comments in multi-line but it doesn't seem to work with regular '\n' newline symbol

"""
  Return:\n true : DB save successful\n false : DB save unsuccessful
"""

This is what i tried

However it outputs exactly the same without putting lines in the new line

Return:\n true : DB save successful\n false : DB save unsuccessful

Is it possible to arrange texts in new line like:

Return:
 true : DB save successful
 false : DB save unsuccessful
J.S.C
  • 1,323
  • 3
  • 16
  • 22

1 Answers1

16

Block strings don't allow escaping characters by design, but you can just utilize new lines inside the string:

"""
Return:
true : DB save successful
false : DB save unsuccessful
"""

Or you can utilize a regular string, which allows escaped characters:

"Return:\n true : DB save successful\n false : DB save unsuccessful"

EDIT:

GraphQL Playground uses this component under the hood to render the descriptions, which itself treats the description as markdown and renders it using markdown-it. Markdown ignores single line breaks, so you would have to use two:

"""
Return:

true : DB save successful

false : DB save unsuccessful
"""
Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183