Skip to content

Commit 4dad893

Browse files
committed
Stable port of Fix printing directives when they contain something like a formatting specifier (#2919) (#2920)
1 parent 9479cc0 commit 4dad893

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎src/main/java/graphql/schema/idl/SchemaPrinter.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ private SchemaElementPrinter<GraphQLInputObjectType> inputObjectPrinter() {
672672
String astValue = printAst(defaultValue, fd.getType());
673673
out.format(" = %s", astValue);
674674
}
675-
out.format(directivesString(GraphQLInputObjectField.class, fd.isDeprecated(), fd));
675+
out.print(directivesString(GraphQLInputObjectField.class, fd.isDeprecated(), fd));
676676
out.format("\n");
677677
});
678678
out.format("}");

‎src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,28 @@ type Query {
20122012
'''
20132013
}
20142014

2015+
def "directive containing formatting specifiers"() {
2016+
def constraintDirective = GraphQLDirective.newDirective().name("constraint")
2017+
.argument({
2018+
it.name("regex").type(GraphQLString).valueProgrammatic("%")
2019+
})
2020+
.build()
2021+
GraphQLInputObjectType type = GraphQLInputObjectType.newInputObject().name("Person")
2022+
.field({ it.name("thisMustBeAPercentageSign").type(GraphQLString).withDirective(constraintDirective) })
2023+
.build()
2024+
2025+
when:
2026+
2027+
def result = new SchemaPrinter().print(type)
2028+
2029+
2030+
then:
2031+
result == '''input Person {
2032+
thisMustBeAPercentageSign: String @constraint(regex : "%")
2033+
}
2034+
'''
2035+
}
2036+
20152037
def "can specify a new ordering for the schema printer"() {
20162038

20172039
def sdl = """

0 commit comments

Comments
 (0)