@@ -148,8 +148,10 @@ private TypePrinter<GraphQLEnumType> enumPrinter() {
148148 if (isIntrospectionType (type )) {
149149 return ;
150150 }
151+ printComments (out , type , "" );
151152 out .format ("enum %s {\n " , type .getName ());
152153 for (GraphQLEnumValueDefinition enumValueDefinition : type .getValues ()) {
154+ printComments (out , enumValueDefinition , " " );
153155 out .format (" %s\n " , enumValueDefinition .getName ());
154156 }
155157 out .format ("}\n \n " );
@@ -193,7 +195,7 @@ private TypePrinter<GraphQLObjectType> objectPrinter() {
193195 if (isIntrospectionType (type )) {
194196 return ;
195197 }
196- printComments (out , type );
198+ printComments (out , type , "" );
197199 out .format ("type %s {\n " , type .getName ());
198200 type .getFieldDefinitions ().forEach (fd -> {
199201 printComments (out , fd , " " );
@@ -335,27 +337,25 @@ private void printType(PrintWriter out, GraphQLType type) {
335337 printer .print (out , type );
336338 }
337339
338- void printComments (PrintWriter out , GraphQLFieldDefinition fieldDefinition , String prefix ) {
339- String description = fieldDefinition .getDescription ();
340- if (description == null ) {
341- return ;
342- }
343- Stream <String > stream = Arrays .stream (description .split ("\n " ));
344- stream .map (s -> prefix + "#" + s + "\n " ).forEach (out ::write );
345- }
346340
347- void printComments (PrintWriter out , GraphQLType graphQLType ) {
341+ private void printComments (PrintWriter out , Object graphQLType , String prefix ) {
348342 String description = getDescription (graphQLType );
349343 if (description == null ) {
350344 return ;
351345 }
352346 Stream <String > stream = Arrays .stream (description .split ("\n " ));
353- stream .map (s -> "#" + s + "\n " ).forEach (out ::write );
347+ stream .map (s -> prefix + "#" + s + "\n " ).forEach (out ::write );
354348 }
355349
356- String getDescription (GraphQLType graphQLType ) {
357- if (graphQLType instanceof GraphQLObjectType ) {
358- return ((GraphQLObjectType ) graphQLType ).getDescription ();
350+ private String getDescription (Object descriptionHolder ) {
351+ if (descriptionHolder instanceof GraphQLObjectType ) {
352+ return ((GraphQLObjectType ) descriptionHolder ).getDescription ();
353+ } else if (descriptionHolder instanceof GraphQLEnumType ) {
354+ return ((GraphQLEnumType ) descriptionHolder ).getDescription ();
355+ } else if (descriptionHolder instanceof GraphQLFieldDefinition ) {
356+ return ((GraphQLFieldDefinition ) descriptionHolder ).getDescription ();
357+ } else if (descriptionHolder instanceof GraphQLEnumValueDefinition ) {
358+ return ((GraphQLEnumValueDefinition ) descriptionHolder ).getDescription ();
359359 } else {
360360 return Assert .assertShouldNeverHappen ();
361361 }
0 commit comments