@@ -3,16 +3,21 @@ package graphql.schema.idl
33import graphql.GraphQL
44import graphql.TestUtil
55import graphql.TypeResolutionEnvironment
6+ import graphql.introspection.Introspection
67import graphql.introspection.IntrospectionQuery
78import graphql.introspection.IntrospectionResultToSchema
89import graphql.language.Comment
10+ import graphql.language.DirectiveDefinition
11+ import graphql.language.EnumValueDefinition
912import graphql.language.FieldDefinition
1013import graphql.language.IntValue
14+ import graphql.language.ScalarTypeDefinition
1115import graphql.language.SchemaDefinition
1216import graphql.language.StringValue
1317import graphql.schema.Coercing
1418import graphql.schema.GraphQLAppliedDirective
1519import graphql.schema.GraphQLCodeRegistry
20+ import graphql.schema.GraphQLDirective
1621import graphql.schema.GraphQLEnumType
1722import graphql.schema.GraphQLEnumValueDefinition
1823import graphql.schema.GraphQLFieldDefinition
@@ -2270,20 +2275,41 @@ type TestObjectB {
22702275
22712276 def " prints AST comments" () {
22722277 given :
2278+ def exampleDirective = GraphQLDirective . newDirective(). name(" example" ). validLocation(Introspection.DirectiveLocation . ENUM_VALUE )
2279+ .description(" custom directive 'example' description 1" )
2280+ .definition(DirectiveDefinition . newDirectiveDefinition(). comments(makeComments(" custom directive 'example' comment 1" )). build()). build()
2281+ def asteroidType = newScalar(). name(" Asteroid" ). description(" desc" )
2282+ .definition(ScalarTypeDefinition . newScalarTypeDefinition(). comments(makeComments(" scalar Asteroid comment 1" )). build())
2283+ .coercing(new Coercing () {
2284+ @Override
2285+ Object serialize (Object input ) {
2286+ throw new UnsupportedOperationException (" Not implemented" )
2287+ }
2288+ @Override
2289+ Object parseValue (Object input ) {
2290+ throw new UnsupportedOperationException (" Not implemented" )
2291+ }
2292+ @Override
2293+ Object parseLiteral (Object input ) {
2294+ throw new UnsupportedOperationException (" Not implemented" )
2295+ }
2296+ })
2297+ .build()
22732298 def nodeType = newInterface(). name(" Node" )
22742299 .field(newFieldDefinition(). name(" id" ). type(nonNull(GraphQLID )). build())
22752300 .build()
22762301 def planetType = newObject(). name(" Planet" )
2277- .field(newFieldDefinition(). name(" hitBy" ). type(this . ASTEROID ). build())
2302+ .field(newFieldDefinition(). name(" hitBy" ). type(asteroidType ). build())
22782303 .field(newFieldDefinition(). name(" name" ). type(GraphQLString ). build())
22792304 .build()
22802305 def episodeType = newEnum(). name(" Episode" )
22812306 .definition(newEnumTypeDefinition(). comments(
22822307 makeComments(" enum Episode comment 1" , " enum Episode comment 2" )). build())
22832308 .values(List . of(
2284- GraphQLEnumValueDefinition . newEnumValueDefinition(). name(" NEWHOPE" ). build(),
2285- GraphQLEnumValueDefinition . newEnumValueDefinition(). name(" EMPIRE" ). build(),
2286- GraphQLEnumValueDefinition . newEnumValueDefinition(). name(" JEDI" ). build()))
2309+ GraphQLEnumValueDefinition . newEnumValueDefinition(). name(" EMPIRE" )
2310+ .definition(EnumValueDefinition . newEnumValueDefinition(). comments(makeComments(" enum value EMPIRE comment 1" )). build()). build(),
2311+ GraphQLEnumValueDefinition . newEnumValueDefinition(). name(" JEDI" ). build(),
2312+ GraphQLEnumValueDefinition . newEnumValueDefinition(). name(" NEWHOPE" ). withDirective(exampleDirective). build()))
22872313 .build()
22882314 def characterType = newInterface(). name(" Character" ). withInterface(nodeType)
22892315 .definition(newInterfaceTypeDefinition(). comments(
@@ -2331,6 +2357,7 @@ type TestObjectB {
23312357 .definition(newInputValueDefinition(). comments(makeComments(" gun 'caliber' input value comment" )). build()). build())
23322358 .build()
23332359 def schema = GraphQLSchema . newSchema()
2360+ .additionalDirective(exampleDirective)
23342361 .codeRegistry(GraphQLCodeRegistry . newCodeRegistry()
23352362 .typeResolver(characterType, { env -> Assert . assertShouldNeverHappen() })
23362363 .typeResolver(humanoidType, { env -> Assert . assertShouldNeverHappen() })
@@ -2349,7 +2376,7 @@ type TestObjectB {
23492376 .query(queryType)
23502377 .build()
23512378 when :
2352- def result = new SchemaPrinter (noDirectivesOption . includeSchemaDefinition(true ). includeAstDefinitionComments(true )). print (schema)
2379+ def result = new SchemaPrinter (defaultOptions() . includeSchemaDefinition(true ). includeAstDefinitionComments(true )). print (schema)
23532380 println (result)
23542381
23552382 then :
@@ -2361,6 +2388,34 @@ schema {
23612388 mutation: Mutation
23622389}
23632390
2391+ "Marks the field, argument, input field or enum value as deprecated"
2392+ directive @deprecated(
2393+ "The reason for the deprecation"
2394+ reason: String = "No longer supported"
2395+ ) on FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM_VALUE | INPUT_FIELD_DEFINITION
2396+
2397+ " custom directive 'example' description 1"
2398+ # custom directive 'example' comment 1
2399+ directive @example on ENUM_VALUE
2400+
2401+ "Directs the executor to include this field or fragment only when the `if` argument is true"
2402+ directive @include(
2403+ "Included when true."
2404+ if: Boolean!
2405+ ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
2406+
2407+ "Directs the executor to skip this field or fragment when the `if` argument is true."
2408+ directive @skip(
2409+ "Skipped when true."
2410+ if: Boolean!
2411+ ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
2412+
2413+ "Exposes a URL that specifies the behaviour of this scalar."
2414+ directive @specifiedBy(
2415+ "The URL that specifies the behaviour of this scalar."
2416+ url: String!
2417+ ) on SCALAR
2418+
23642419# interface Character comment 1
23652420# interface Character comment 2
23662421interface Character implements Node {
@@ -2420,12 +2475,14 @@ type Query {
24202475# enum Episode comment 1
24212476# enum Episode comment 2
24222477enum Episode {
2478+ # enum value EMPIRE comment 1
24232479 EMPIRE
24242480 JEDI
2425- NEWHOPE
2481+ NEWHOPE @example
24262482}
24272483
24282484"desc"
2485+ # scalar Asteroid comment 1
24292486scalar Asteroid
24302487
24312488# input type Gun comment 1
0 commit comments