Skip to content

Commit 69e18bb

Browse files
oryan-blockclaude
andcommitted
Add the directive definitions to the read-only schema
Scalars carry their directives now, so a schema whose only custom directives are on scalars failed toReadOnlySchema() with "A definition for directive could not be found", like one with a custom directive on a field already did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent cb1deee commit 69e18bb

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎src/main/kotlin/graphql/kickstart/tools/SchemaObjects.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ data class SchemaObjects @JvmOverloads constructor(
6464
.description(description)
6565
.query(query)
6666
.additionalTypes(namedDictionary())
67+
.additionalDirectives(directives)
6768
.build()
6869
}

‎src/test/kotlin/graphql/kickstart/tools/DirectiveTest.kt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ class DirectiveTest {
676676
@Test
677677
fun `should apply the schema's directives and the provided specifiedBy URL to scalars`() {
678678
val wired = mutableListOf<String>()
679-
val schema = SchemaParser.newParser()
679+
val parser = SchemaParser.newParser()
680680
.schemaString(
681681
"""
682682
directive @unit(name: String!) on SCALAR
@@ -707,8 +707,7 @@ class DirectiveTest {
707707
}
708708
})
709709
.build()
710-
.makeExecutableSchema()
711-
.assertEveryFieldResolves()
710+
val schema = parser.makeExecutableSchema().assertEveryFieldResolves()
712711

713712
val data = assertNoGraphQlErrors(GraphQL.newGraphQL(schema).build()) {
714713
"""
@@ -728,6 +727,7 @@ class DirectiveTest {
728727
assertEquals(date.appliedDirectives.map { it.name }, listOf("specifiedBy", "unit"))
729728
val printed = SchemaPrinter().print(schema)
730729
assert(printed.contains("""@specifiedBy(url : "https://example.com/date")""")) { printed }
730+
assertEquals(parser.parseSchemaObjects().toReadOnlySchema().getDirective("unit")?.name, "unit")
731731
}
732732

733733
@Test

0 commit comments

Comments
 (0)