forked from pgutkowski/KGraphQL
-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
I have many different resources for which I define the same kind of queries or mutations, ie. getting all entities, getting an entity by id, getting the count etc.
So I tried to write a generic function which constructs these queries on the SchemaBuilder, something like this:
fun <T> SchemaBuilder.sharedQueries(resourceName: String, repository: Repository<T>) {
query("${resourceName}s") {
resolver { ctx: Context ->
repository.getAll()
}
}
query(resourceName) {
resolver { id: Int, ctx: Context ->
repository.get(id)
}
}
query("${resourceName}Count") {
resolver { ctx: Context ->
repository.count()
}
}
}Which is then called like so:
schema {
sharedQueries<User>("user", userRepository)
sharedQueries<Role>("role", roleRepository)
// etc.
}
However, this fails because the generic is not yet resolved when the reflection is at work, resulting in this exception:
Caused by: kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Container of deserialized member is not resolved: local final fun <T> <anonymous>(id: Int, ctx: com.apurebase.kgraphql.Context): T[DeserializedSimpleFunctionDescriptor@3ff57625]
at kotlin.reflect.jvm.internal.KTypeParameterImpl.getContainerClass(KTypeParameterImpl.kt:79)
Inlining also doesn't help.
So my question is, is there some other way to avoid writing structurally identical queries all the time?
jeggyESchouten
Metadata
Metadata
Assignees
Labels
No labels