@@ -110,7 +110,7 @@ private NodePrinter<DirectiveLocation> directiveLocation() {
110110
111111 private NodePrinter <EnumTypeDefinition > enumTypeDefinition () {
112112 return (out , node ) -> {
113- out .printf ("%s" , comments (node ));
113+ out .printf ("%s" , description (node ));
114114 out .printf ("%s" ,
115115 spaced (
116116 "enum" ,
@@ -127,7 +127,7 @@ private NodePrinter<EnumValue> enumValue() {
127127
128128 private NodePrinter <EnumValueDefinition > enumValueDefinition () {
129129 return (out , node ) -> {
130- out .printf ("%s" , comments (node ));
130+ out .printf ("%s" , description (node ));
131131 out .printf ("%s" ,
132132 spaced (
133133 node .getName (),
@@ -158,12 +158,12 @@ private NodePrinter<Field> field() {
158158 private NodePrinter <FieldDefinition > fieldDefinition () {
159159 final String argSep = compactMode ? "," : ", " ;
160160 return (out , node ) -> {
161- out .printf ("%s" , comments (node ));
162161 String args ;
163- if (hasComments (node .getInputValueDefinitions ()) && !compactMode ) {
162+ if (hasDescription (node .getInputValueDefinitions ()) && !compactMode ) {
163+ out .printf ("%s" , description (node ));
164164 args = join (node .getInputValueDefinitions (), "\n " );
165165 out .printf ("%s" , node .getName () +
166- wrap ("(\n " , args , "\n )" ) +
166+ wrap ("(\n " , args , ")" ) +
167167 ": " +
168168 spaced (
169169 type (node .getType ()),
@@ -173,7 +173,7 @@ private NodePrinter<FieldDefinition> fieldDefinition() {
173173 } else {
174174 args = join (node .getInputValueDefinitions (), argSep );
175175 out .printf ("%s" , node .getName () +
176- wrap ("(" , args , ")" ) +
176+ wrap ( "(" , args , ")" ) +
177177 ": " +
178178 spaced (
179179 type (node .getType ()),
@@ -184,8 +184,16 @@ private NodePrinter<FieldDefinition> fieldDefinition() {
184184 };
185185 }
186186
187- private boolean hasComments (List <? extends Node > nodes ) {
188- return nodes .stream ().anyMatch (it -> it .getComments ().size () > 0 );
187+ // private boolean hasDescription(Node<?> node) {
188+ // Description description = ((AbstractDescribedNode) node).getDescription();
189+ // if (description == null || description.getContent() == null || description.getContent().length() == 0 ) {
190+ // return false;
191+ // }
192+ // return true;
193+ // }
194+
195+ private boolean hasDescription (List <? extends Node > nodes ) {
196+ return nodes .stream ().anyMatch (it -> ((AbstractDescribedNode ) it ).getDescription () != null );
189197 }
190198
191199 private NodePrinter <FragmentDefinition > fragmentDefinition () {
@@ -217,7 +225,6 @@ private NodePrinter<InlineFragment> inlineFragment() {
217225 String directives = directives (node .getDirectives ());
218226 String selectionSet = node (node .getSelectionSet ());
219227
220- out .printf ("%s" , comments (node ));
221228 out .printf ("%s" , spaced (
222229 "..." ,
223230 typeCondition ,
@@ -229,7 +236,7 @@ private NodePrinter<InlineFragment> inlineFragment() {
229236
230237 private NodePrinter <InputObjectTypeDefinition > inputObjectTypeDefinition () {
231238 return (out , node ) -> {
232- out .printf ("%s" , comments (node ));
239+ out .printf ("%s" , description (node ));
233240 out .printf ("%s" , spaced (
234241 "input" ,
235242 node .getName (),
@@ -245,7 +252,7 @@ private NodePrinter<InputValueDefinition> inputValueDefinition() {
245252 String defaultValueEquals = compactMode ? "=" : "= " ;
246253 return (out , node ) -> {
247254 Value defaultValue = node .getDefaultValue ();
248- out .printf ("%s" , comments (node ));
255+ out .printf ("%s" , description (node ));
249256 out .printf ("%s" , spaced (
250257 node .getName () + nameTypeSep + type (node .getType ()),
251258 wrap (defaultValueEquals , defaultValue , "" ),
@@ -257,7 +264,7 @@ private NodePrinter<InputValueDefinition> inputValueDefinition() {
257264
258265 private NodePrinter <InterfaceTypeDefinition > interfaceTypeDefinition () {
259266 return (out , node ) -> {
260- out .printf ("%s" , comments (node ));
267+ out .printf ("%s" , description (node ));
261268 out .printf ("%s" , spaced (
262269 "interface" ,
263270 node .getName (),
@@ -300,7 +307,7 @@ private NodePrinter<OperationTypeDefinition> operationTypeDefinition() {
300307
301308 private NodePrinter <ObjectTypeDefinition > objectTypeDefinition () {
302309 return (out , node ) -> {
303- out .printf ("%s" , comments (node ));
310+ out .printf ("%s" , description (node ));
304311 out .printf ("%s" , spaced (
305312 "type" ,
306313 node .getName (),
@@ -313,14 +320,13 @@ private NodePrinter<ObjectTypeDefinition> objectTypeDefinition() {
313320
314321 private NodePrinter <SelectionSet > selectionSet () {
315322 return (out , node ) -> {
316- out .printf ("%s" , comments (node ));
317323 out .printf ("%s" , block (node .getSelections ()));
318324 };
319325 }
320326
321327 private NodePrinter <ScalarTypeDefinition > scalarTypeDefinition () {
322328 return (out , node ) -> {
323- out .printf ("%s" , comments (node ));
329+ out .printf ("%s" , description (node ));
324330 out .printf ("%s" , spaced (
325331 "scalar" ,
326332 node .getName (),
@@ -331,7 +337,6 @@ private NodePrinter<ScalarTypeDefinition> scalarTypeDefinition() {
331337
332338 private NodePrinter <SchemaDefinition > schemaDefinition () {
333339 return (out , node ) -> {
334- out .printf ("%s" , comments (node ));
335340 out .printf ("%s" , spaced (
336341 "schema" ,
337342 directives (node .getDirectives ()),
@@ -387,7 +392,7 @@ private NodePrinter<UnionTypeDefinition> unionTypeDefinition() {
387392 String barSep = compactMode ? "|" : " | " ;
388393 String equals = compactMode ? "=" : "= " ;
389394 return (out , node ) -> {
390- out .printf ("%s" , comments (node ));
395+ out .printf ("%s" , description (node ));
391396 out .printf ("%s" , spaced (
392397 "union" ,
393398 node .getName (),
@@ -489,16 +494,21 @@ private String value(Value value) {
489494 return "" ;
490495 }
491496
492- private String comments (Node <?> node ) {
493- List < Comment > comments = nvl ( node . getComments () );
494- if (isEmpty ( comments ) || compactMode ) {
497+ private String description (Node <?> node ) {
498+ Description description = (( AbstractDescribedNode ) node ). getDescription ( );
499+ if (description == null || description . getContent () == null || compactMode ) {
495500 return "" ;
496501 }
497- String s = comments .stream ().map (c -> "#" + c .getContent ()).collect (joining ("\n " , "" , "\n " ));
502+ String s ;
503+ boolean startNewLine = description .getContent ().charAt (0 ) == '\n' ;
504+ if (description .isMultiLine ()) {
505+ s = "\" \" \" " + (startNewLine ? "" : "\n " ) + description .getContent () + "\n \" \" \" \n " ;
506+ } else {
507+ s = "\" " + description .getContent () + "\" \n " ;
508+ }
498509 return s ;
499510 }
500511
501-
502512 private String directives (List <Directive > directives ) {
503513 return join (nvl (directives ), " " );
504514 }
0 commit comments