Skip to content

Commit 7e2b4fb

Browse files
committed
Add support for unused types for all dictionary types
1 parent 1699147 commit 7e2b4fb

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,13 @@ internal class SchemaClassScanner(
9191
do {
9292
val unusedDefinitions = (definitionsByName.values - (dictionary.keys.toSet() + unvalidatedTypes))
9393
.filter { definition -> definition.name != "PageInfo" }
94-
.filterIsInstance<ObjectTypeDefinition>().distinct()
94+
.distinct()
9595

9696
if (unusedDefinitions.isEmpty()) {
9797
break
9898
}
9999

100-
val unusedDefinition = unusedDefinitions.first()
101-
102-
handleDictionaryTypes(listOf(unusedDefinition)) { "Object type '${it.name}' is unused and includeUnusedTypes is true. Please pass a class for type '${it.name}' in the parser's dictionary." }
100+
handleDictionaryTypes(unusedDefinitions) { "Type '${it.name}' is unused and includeUnusedTypes is true. Please pass a class for type '${it.name}' in the parser's dictionary." }
103101
} while (scanQueue())
104102
}
105103

@@ -229,7 +227,7 @@ internal class SchemaClassScanner(
229227
}.flatten().distinct()
230228
}
231229

232-
private fun handleDictionaryTypes(types: List<ObjectTypeDefinition>, failureMessage: (ObjectTypeDefinition) -> String) {
230+
private fun handleDictionaryTypes(types: List<TypeDefinition<*>>, failureMessage: (TypeDefinition<*>) -> String) {
233231
types.forEach { type ->
234232
val dictionaryContainsType = dictionary.filter { it.key.name == type.name }.isNotEmpty()
235233
if (!unvalidatedTypes.contains(type) && !dictionaryContainsType) {

src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerTest.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,19 @@ class SchemaClassScannerTest {
497497
type Implementation implements SomeInterface {
498498
value: String
499499
}
500+
501+
union SomeUnion = Unused | Implementation
502+
503+
enum SomeEnum {
504+
A
505+
B
506+
}
500507
""")
501508
.resolvers(object : GraphQLQueryResolver {
502509
fun whatever(): Whatever? = null
503510
})
504511
.options(SchemaParserOptions.newOptions().includeUnusedTypes(true).build())
505-
.dictionary(Unused::class, Implementation::class)
512+
.dictionary(Unused::class, Implementation::class, SomeInterface::class, SomeUnion::class, SomeEnum::class)
506513
.build()
507514
.makeExecutableSchema()
508515

src/test/kotlin/graphql/kickstart/tools/TestInterfaces.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ interface SomeInterface {
1414
fun getValue(): String?
1515
}
1616

17+
interface SomeUnion
18+
19+
enum class SomeEnum {
20+
A,
21+
B
22+
}
23+

0 commit comments

Comments
 (0)