Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ internal class SchemaClassScanner(
do {
val unusedDefinitions = (definitionsByName.values - (dictionary.keys.toSet() + unvalidatedTypes))
.filter { definition -> definition.name != "PageInfo" }
.filterIsInstance<ObjectTypeDefinition>().distinct()
.filter { isCompositeOrEnumType(it) }
.distinct()

if (unusedDefinitions.isEmpty()) {
break
}

val unusedDefinition = unusedDefinitions.first()

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." }
handleDictionaryTypes(unusedDefinitions) { "Type '${it.name}' is unused and includeUnusedTypes is true. Please pass a class for type '${it.name}' in the parser's dictionary." }
} while (scanQueue())
}

Expand All @@ -108,6 +107,10 @@ internal class SchemaClassScanner(
return validateAndCreateResult(rootTypeHolder)
}

private fun isCompositeOrEnumType(definition: TypeDefinition<*>): Boolean {
return definition is ObjectTypeDefinition || definition is InterfaceTypeDefinition || definition is UnionTypeDefinition || definition is EnumTypeDefinition
}

private fun scanQueue(): Boolean {
if (queue.isEmpty()) {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,19 @@ class SchemaClassScannerTest {
type Implementation implements SomeInterface {
value: String
}

union SomeUnion = Unused | Implementation

enum SomeEnum {
A
B
}
""")
.resolvers(object : GraphQLQueryResolver {
fun whatever(): Whatever? = null
})
.options(SchemaParserOptions.newOptions().includeUnusedTypes(true).build())
.dictionary(Unused::class, Implementation::class)
.dictionary(Unused::class, Implementation::class, SomeInterface::class, SomeUnion::class, SomeEnum::class)
.build()
.makeExecutableSchema()

Expand Down
7 changes: 7 additions & 0 deletions src/test/kotlin/graphql/kickstart/tools/TestInterfaces.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ interface SomeInterface {
fun getValue(): String?
}

interface SomeUnion

enum class SomeEnum {
A,
B
}

Loading