aPureBase / KGraphQL

Pure Kotlin GraphQL implementation
https://kgraphql.io
MIT License
301 stars 58 forks source link

Use correct KType when custom InputValue is provided #143

Closed ESchouten closed 3 years ago

ESchouten commented 3 years ago

When a custom InputTypeDef is provided, the kqlInput is correctly set, but the inputType is not.

Due to kotlins reflection behaviour, which returns functions with generic types instead of the underlying types, overriding the input type seems mandatory. https://youtrack.jetbrains.com/issue/KT-42746 Doing so enables the use of generics discussed in #139

Example:

inline fun <reified T : Any, reified U : Any, V: UseCase<T, U>> SchemaBuilder.connection(usecase: V) {
    query(usecase::class.simpleName!!) {
        resolver { request: T, ctx: Context ->
            usecase.execute(request, ctx.get<User>())
        }.returns<U>().apply {
            addInputValues(listOf(InputValueDef(T::class, "request")))
        }
    }
}