@@ -2428,4 +2428,94 @@ class FastBuilderTest extends Specification {
24282428 ! (resolvedApplied. getArgument(" color" ). type instanceof GraphQLTypeReference )
24292429 resolvedApplied. getArgument(" color" ). type == colorEnum
24302430 }
2431+
2432+ def " legacy directive on directive definition with type-ref enum arg resolves correctly" () {
2433+ given : " a Color enum type used as the legacy directive argument type"
2434+ def colorEnum = newEnum()
2435+ .name(" Color" )
2436+ .value(" RED" )
2437+ .value(" GREEN" )
2438+ .build()
2439+
2440+ and : " a legacy directive on another directive definition with an unresolved type ref"
2441+ def legacyMeta = newDirective()
2442+ .name(" meta" )
2443+ .validLocation(Introspection.DirectiveLocation . DIRECTIVE_DEFINITION )
2444+ .argument(newArgument()
2445+ .name(" color" )
2446+ .type(typeRef(" Color" ))
2447+ .valueLiteral(new EnumValue (" GREEN" )))
2448+ .build()
2449+
2450+ and : " a directive definition with the legacy directive"
2451+ def targetDirective = newDirective()
2452+ .name(" target" )
2453+ .validLocation(Introspection.DirectiveLocation . FIELD_DEFINITION )
2454+ .withDirective(legacyMeta)
2455+ .build()
2456+
2457+ and : " a query type"
2458+ def queryType = newObject()
2459+ .name(" Query" )
2460+ .field(newFieldDefinition()
2461+ .name(" field" )
2462+ .type(GraphQLString ))
2463+ .build()
2464+
2465+ when : " building with FastBuilder"
2466+ def schema = new GraphQLSchema.FastBuilder (
2467+ GraphQLCodeRegistry . newCodeRegistry(), queryType, null , null )
2468+ .addType(colorEnum)
2469+ .additionalDirective(targetDirective)
2470+ .build()
2471+
2472+ then : " schema builds successfully and the legacy directive arg type is resolved"
2473+ schema != null
2474+ def resolvedTarget = schema. getDirective(" target" )
2475+ def resolvedLegacy = resolvedTarget. getDirective(" meta" )
2476+ resolvedLegacy != null
2477+ ! (resolvedLegacy. getArgument(" color" ). type instanceof GraphQLTypeReference )
2478+ resolvedLegacy. getArgument(" color" ). type == colorEnum
2479+ }
2480+
2481+ def " legacy directive on object type with type-ref enum arg resolves correctly" () {
2482+ given : " a Color enum type used as the legacy directive argument type"
2483+ def colorEnum = newEnum()
2484+ .name(" Color" )
2485+ .value(" RED" )
2486+ .value(" GREEN" )
2487+ .build()
2488+
2489+ and : " a legacy directive on an object type with an unresolved type ref"
2490+ def legacyMeta = newDirective()
2491+ .name(" meta" )
2492+ .validLocation(Introspection.DirectiveLocation . OBJECT )
2493+ .argument(newArgument()
2494+ .name(" color" )
2495+ .type(typeRef(" Color" ))
2496+ .valueLiteral(new EnumValue (" GREEN" )))
2497+ .build()
2498+
2499+ and : " a query type with the legacy directive"
2500+ def queryType = newObject()
2501+ .name(" Query" )
2502+ .withDirective(legacyMeta)
2503+ .field(newFieldDefinition()
2504+ .name(" field" )
2505+ .type(GraphQLString ))
2506+ .build()
2507+
2508+ when : " building with FastBuilder"
2509+ def schema = new GraphQLSchema.FastBuilder (
2510+ GraphQLCodeRegistry . newCodeRegistry(), queryType, null , null )
2511+ .addType(colorEnum)
2512+ .build()
2513+
2514+ then : " schema builds successfully and the legacy directive arg type is resolved"
2515+ schema != null
2516+ def resolvedLegacy = schema. queryType. getDirective(" meta" )
2517+ resolvedLegacy != null
2518+ ! (resolvedLegacy. getArgument(" color" ). type instanceof GraphQLTypeReference )
2519+ resolvedLegacy. getArgument(" color" ). type == colorEnum
2520+ }
24312521}
0 commit comments