Skip to content

Commit 17b8f56

Browse files
andimarekbbakerman
authored andcommitted
print object descriptions
1 parent d212399 commit 17b8f56

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/main/java/graphql/schema/idl/SchemaPrinter.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import java.io.PrintWriter;
1919
import java.io.StringWriter;
2020
import java.util.ArrayList;
21+
import java.util.Arrays;
2122
import java.util.Comparator;
2223
import java.util.LinkedHashMap;
2324
import java.util.List;
2425
import java.util.Map;
2526
import java.util.Stack;
27+
import java.util.stream.Stream;
2628

2729
/**
2830
* This can print an in memory GraphQL schema back to a logical schema definition
@@ -58,7 +60,6 @@ public static Options defaultOptions() {
5860
* This will allow you to include introspection types that are contained in a schema
5961
*
6062
* @param flag whether to include them
61-
*
6263
* @return options
6364
*/
6465
public Options includeIntrospectionTypes(boolean flag) {
@@ -69,7 +70,6 @@ public Options includeIntrospectionTypes(boolean flag) {
6970
* This will allow you to include scalar types that are contained in a schema
7071
*
7172
* @param flag whether to include them
72-
*
7373
* @return options
7474
*/
7575
public Options includeScalarTypes(boolean flag) {
@@ -99,7 +99,6 @@ public SchemaPrinter(Options options) {
9999
* This can print an in memory GraphQL schema back to a logical schema definition
100100
*
101101
* @param schema the schema in play
102-
*
103102
* @return the logical schema definition
104103
*/
105104
public String print(GraphQLSchema schema) {
@@ -192,6 +191,7 @@ private TypePrinter<GraphQLObjectType> objectPrinter() {
192191
if (isIntrospectionType(type)) {
193192
return;
194193
}
194+
printComments(out, type);
195195
out.format("type %s {\n", type.getName());
196196
type.getFieldDefinitions().forEach(fd ->
197197
out.format(" %s%s : %s\n",
@@ -330,4 +330,12 @@ private void printType(PrintWriter out, GraphQLType type) {
330330
TypePrinter<Object> printer = printer(type.getClass());
331331
printer.print(out, type);
332332
}
333+
334+
void printComments(PrintWriter out, GraphQLObjectType graphQLType) {
335+
if (graphQLType.getDescription() == null) {
336+
return;
337+
}
338+
Stream<String> stream = Arrays.stream(graphQLType.getDescription().split("\n"));
339+
stream.map(s -> "#" + s + "\n").forEach(out::write);
340+
}
333341
}

0 commit comments

Comments
 (0)