File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
main/java/graphql/schema/idl
test/groovy/graphql/schema/idl Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ private TypePrinter<GraphQLScalarType> scalarPrinter() {
140140 return ;
141141 }
142142 if (!ScalarInfo .isStandardScalar (type )) {
143+ printComments (out , type , "" );
143144 out .format ("scalar %s\n \n " , type .getName ());
144145 }
145146 };
@@ -373,6 +374,8 @@ private String getDescription(Object descriptionHolder) {
373374 return ((GraphQLInputObjectField ) descriptionHolder ).getDescription ();
374375 } else if (descriptionHolder instanceof GraphQLInterfaceType ) {
375376 return ((GraphQLInterfaceType ) descriptionHolder ).getDescription ();
377+ } else if (descriptionHolder instanceof GraphQLScalarType ) {
378+ return ((GraphQLScalarType ) descriptionHolder ).getDescription ();
376379 } else {
377380 return Assert .assertShouldNeverHappen ();
378381 }
Original file line number Diff line number Diff line change @@ -434,6 +434,42 @@ type Query {
434434 field : Interface
435435}
436436
437+ """
438+ }
439+
440+ def " prints scalar description as comment" () {
441+ given :
442+ GraphQLScalarType myScalar = new GraphQLScalarType (" Scalar" , " about scalar" , new Coercing () {
443+ @Override
444+ Object serialize (Object input ) {
445+ return null
446+ }
447+
448+ @Override
449+ Object parseValue (Object input ) {
450+ return null
451+ }
452+
453+ @Override
454+ Object parseLiteral (Object input ) {
455+ return null
456+ }
457+ });
458+ GraphQLFieldDefinition fieldDefinition = newFieldDefinition()
459+ .name(" field" ). type(myScalar). build()
460+ def queryType = GraphQLObjectType . newObject(). name(" Query" ). field(fieldDefinition). build()
461+ def schema = GraphQLSchema . newSchema(). query(queryType). build()
462+ when :
463+ def result = new SchemaPrinter (SchemaPrinter.Options . defaultOptions(). includeScalarTypes(true )). print (schema)
464+
465+ then :
466+ result == """ type Query {
467+ field : Scalar
468+ }
469+
470+ #about scalar
471+ scalar Scalar
472+
437473"""
438474 }
439475
You can’t perform that action at this time.
0 commit comments