Skip to content

Commit f361f4f

Browse files
andimarekclaude
andcommitted
Add test for modifying a built-in directive via SchemaTransformer
Verifies that a built-in directive (e.g. @deprecated) can be modified by adding a new argument through SchemaTransformer, and that all other built-in directives remain unchanged after the transformation. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e1b5c3c commit f361f4f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/test/groovy/graphql/schema/SchemaTransformerTest.groovy

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,4 +1464,53 @@ type Rental {
14641464
e.getMessage().contains("All types within a GraphQL schema must have unique names")
14651465
e.getMessage().contains("ExistingType")
14661466
}
1467+
1468+
def "can modify a built-in directive via schema transformation"() {
1469+
given:
1470+
GraphQLSchema schema = TestUtil.schema("""
1471+
type Query {
1472+
hello: String @deprecated(reason: "use goodbye")
1473+
goodbye: String
1474+
}
1475+
""")
1476+
1477+
when:
1478+
GraphQLSchema newSchema = SchemaTransformer.transformSchema(schema, new GraphQLTypeVisitorStub() {
1479+
@Override
1480+
TraversalControl visitGraphQLDirective(GraphQLDirective node, TraverserContext<GraphQLSchemaElement> context) {
1481+
if (node.getName() == "deprecated") {
1482+
def changedNode = node.transform({ builder ->
1483+
builder.argument(GraphQLArgument.newArgument()
1484+
.name("deletionDate")
1485+
.type(Scalars.GraphQLString)
1486+
.description("The date when this field will be removed"))
1487+
})
1488+
return changeNode(context, changedNode)
1489+
}
1490+
return TraversalControl.CONTINUE
1491+
}
1492+
})
1493+
1494+
then: "the modified built-in directive has the new argument"
1495+
def deprecatedDirective = newSchema.getDirective("deprecated")
1496+
deprecatedDirective != null
1497+
deprecatedDirective.getArguments().size() == 2
1498+
deprecatedDirective.getArgument("reason") != null
1499+
deprecatedDirective.getArgument("deletionDate") != null
1500+
deprecatedDirective.getArgument("deletionDate").getType() == Scalars.GraphQLString
1501+
1502+
and: "other built-in directives remain unchanged"
1503+
newSchema.getDirective("include").getArguments().size() == 1
1504+
newSchema.getDirective("skip").getArguments().size() == 1
1505+
1506+
and: "all built-in directives are still present"
1507+
newSchema.getDirective("include") != null
1508+
newSchema.getDirective("skip") != null
1509+
newSchema.getDirective("deprecated") != null
1510+
newSchema.getDirective("specifiedBy") != null
1511+
newSchema.getDirective("oneOf") != null
1512+
newSchema.getDirective("defer") != null
1513+
newSchema.getDirective("experimental_disableErrorPropagation") != null
1514+
newSchema.getDirectives().size() == schema.getDirectives().size()
1515+
}
14671516
}

0 commit comments

Comments
 (0)