@@ -6,6 +6,8 @@ import graphql.schema.Coercing
66import graphql.schema.GraphQLArgument
77import graphql.schema.GraphQLEnumType
88import graphql.schema.GraphQLFieldDefinition
9+ import graphql.schema.GraphQLInputObjectType
10+ import graphql.schema.GraphQLInputType
911import graphql.schema.GraphQLList
1012import graphql.schema.GraphQLNonNull
1113import graphql.schema.GraphQLObjectType
@@ -18,7 +20,10 @@ import spock.lang.Specification
1820
1921import java.util.function.UnaryOperator
2022
23+ import static graphql.Scalars.GraphQLString
24+ import static graphql.schema.GraphQLArgument.newArgument
2125import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition
26+ import static graphql.schema.GraphQLInputObjectField.newInputObjectField
2227
2328class SchemaPrinterTest extends Specification {
2429
@@ -95,8 +100,8 @@ class SchemaPrinterTest extends Specification {
95100
96101 def " argsString" () {
97102 def argument1 = new GraphQLArgument (" arg1" , " desc-arg1" , list(nonNull(Scalars.GraphQLInt )), 10 )
98- def argument2 = new GraphQLArgument (" arg2" , " desc-arg2" , Scalars. GraphQLString , null )
99- def argument3 = new GraphQLArgument (" arg3" , " desc-arg3" , Scalars. GraphQLString , " default" )
103+ def argument2 = new GraphQLArgument (" arg2" , " desc-arg2" , GraphQLString , null )
104+ def argument3 = new GraphQLArgument (" arg3" , " desc-arg3" , GraphQLString , " default" )
100105 def argStr = new SchemaPrinter (). argsString([argument1, argument2, argument3])
101106
102107 expect :
@@ -232,7 +237,7 @@ type Subscription {
232237 def " prints object description as comment" () {
233238 given :
234239 GraphQLFieldDefinition fieldDefinition = newFieldDefinition()
235- .name(" field" ). type(Scalars. GraphQLString ). build()
240+ .name(" field" ). type(GraphQLString ). build()
236241 def queryType = GraphQLObjectType . newObject(). name(" Query" ). description(" About Query\n Second Line" ). field(fieldDefinition). build()
237242 def schema = GraphQLSchema . newSchema(). query(queryType). build()
238243 when :
@@ -251,7 +256,7 @@ type Query {
251256 def " prints field description as comment" () {
252257 given :
253258 GraphQLFieldDefinition fieldDefinition = newFieldDefinition()
254- .name(" field" ). description(" About field\n second" ). type(Scalars. GraphQLString ). build()
259+ .name(" field" ). description(" About field\n second" ). type(GraphQLString ). build()
255260 def queryType = GraphQLObjectType . newObject(). name(" Query" ). field(fieldDefinition). build()
256261 def schema = GraphQLSchema . newSchema(). query(queryType). build()
257262 when :
@@ -300,7 +305,7 @@ enum Enum {
300305 def " prints union description as comment" () {
301306 given :
302307 GraphQLFieldDefinition fieldDefinition = newFieldDefinition()
303- .name(" field" ). type(Scalars. GraphQLString ). build()
308+ .name(" field" ). type(GraphQLString ). build()
304309 def possibleType = GraphQLObjectType . newObject(). name(" PossibleType" ). field(fieldDefinition). build()
305310 GraphQLUnionType unionType = GraphQLUnionType . newUnionType()
306311 .name(" Union" )
@@ -333,10 +338,10 @@ type Query {
333338
334339 def " prints union" () {
335340 def possibleType1 = GraphQLObjectType . newObject(). name(" PossibleType1" ). field(
336- newFieldDefinition(). name(" field" ). type(Scalars. GraphQLString ). build()
341+ newFieldDefinition(). name(" field" ). type(GraphQLString ). build()
337342 ). build()
338343 def possibleType2 = GraphQLObjectType . newObject(). name(" PossibleType2" ). field(
339- newFieldDefinition(). name(" field" ). type(Scalars. GraphQLString ). build()
344+ newFieldDefinition(). name(" field" ). type(GraphQLString ). build()
340345 ). build()
341346 GraphQLUnionType unionType = GraphQLUnionType . newUnionType()
342347 .name(" Union" )
@@ -370,4 +375,36 @@ type Query {
370375
371376 }
372377
378+ def " prints input description as comment" () {
379+ given :
380+ GraphQLInputType inputType = GraphQLInputObjectType . newInputObject()
381+ .name(" Input" )
382+ .field(newInputObjectField(). name(" field" ). description(" about field" ). type(GraphQLString ). build())
383+ .description(" About input" )
384+ .build()
385+ GraphQLFieldDefinition fieldDefinition2 = newFieldDefinition()
386+ .name(" field" )
387+ .argument(newArgument(). name(" arg" ). type(inputType). build())
388+ .type(GraphQLString ). build()
389+ def queryType = GraphQLObjectType . newObject(). name(" Query" ). field(fieldDefinition2). build()
390+ def schema = GraphQLSchema . newSchema(). query(queryType). build()
391+ when :
392+ def result = new SchemaPrinter (). print (schema)
393+
394+ then :
395+ result == """ type Query {
396+ field(arg : Input) : String
397+ }
398+
399+ #About input
400+ input Input {
401+ #about field
402+ field : String
403+ }
404+
405+ """
406+
407+ }
408+
409+
373410}
0 commit comments