-
Notifications
You must be signed in to change notification settings - Fork 60
Description
I want to suggest a possible way for the library to handle generic types without requiring behavior that is explicitly defined by the user.
I've been messing around a bit with the codebase and it seems like the problem is that the lookup in some caches and functions is KClass<*>.
KType.jvmErasure will erase the provided generic type.
We need to retain the information in the KType object.
So i tried to replace the lookup type with a combination of KType and KClass<*> and the result seems promising.
I think maybe just KType may be enough but my understanding of the codebase is still very limited.
I'm not entirely sure how this would be combined with the existing user provided generic type resolver.
I think we could run it through the provided type resolver first and then let the system process it after if the returned type still has atleast one generic type parameter.
Idea here is that we construct a new type for each combination of the provided generic type.
MyGenericType<MyUser> becomes MyGenericType_MyUser
MyGenericType<MyDirectory> becomes MyGenericType_MyDirectory
class MyGenericType<T>(
val name: String,
val value: T
)
class MyUser(
val name: String,
val id: Int
)
class MyDirectory(
val name: String,
val id: Int
)
private fun a(): MyGenericType<MyUser> {
TODO()
}
private fun b(): MyGenericType<MyDirectory> {
TODO()
}
private fun c(): MyGenericType<MyUser> {
TODO()
}
@Test
fun `generic type handling`() {
val testedSchema = defaultSchema {
query("myTest1") {
resolver<MyGenericType<MyUser>> {
a()
}
}
query("myTest2") {
resolver<MyGenericType<MyDirectory>> {
b()
}
}
query("myTest3") {
resolver<MyGenericType<MyUser>> {
c()
}
}
}
val typeNames = testedSchema.model.types.map { it.name }
typeNames.forEach { println(it) }
}Ouput
__Schema
__Directive
__InputValue
__Type
__EnumValue
__Field
__Type
__Type
__Directive
MyGenericType_MyUser
MyUser
MyGenericType_MyDirectory
MyDirectory
__Schema
__TypeKind
__DirectiveLocation
String
Boolean
Float
Short
Int
Long
Query
I was considering a pull request myself but i think my code is just a bit too messy.