hello! :wave: I’m hitting a pretty weird error fro...
# ktor
d
hello! 👋 I’m hitting a pretty weird error from
HttpClient
and I am unsure whats causing it, given some result object when I run the following
Copy code
lateinit var result: GraphQLResult<ExampleQuery.ExampleQueryResult>
runBlocking {
    val graphQLRequest = mapOf(
            "query" to EXAMPLE_QUERY,
            "operationName" to "ExampleQuery",
            "variables" to variables
    )
    result = <http://ktorClient.post|ktorClient.post>("<http://localhost:8080/graphql>") {
        accept(ContentType.Application.Json)
        contentType(ContentType.Application.Json)
        body = graphQLRequest
    }
    // works fine
    println("ktor: ${result.data}")

    val myClient = MyClient(ktorClient, "<http://localhost:8080/graphql>")
    result = myClient.executeOperation(EXAMPLE_QUERY, "ExampleQuery", variables)
    // blows up saying cannot cast linked hash map to my result object
    println("myClient: ${result.data}")
}

class MyClient(val client: HttpClient, val url: String) {
    suspend fun <T> executeOperation(query: String, operationName: String? = null, variables: Any? = null): GraphQLResult<T> {
        val graphQLRequest = mapOf(
                "query" to query,
                "operationName" to operationName,
                "variables" to variables
        )

        return <http://client.post|client.post>(url) {
            accept(ContentType.Application.Json)
            contentType(ContentType.Application.Json)
            body = graphQLRequest
        }
    }
}
any ideas why it would behave differently?
looks like changing
MyClient
to drop the generics and use
suspend fun executeOperation(query: String, operationName: String? = null, variables: Any? = null): GraphQLResult<ExampleQuery.ExampleQueryResult>
works
any idea how I could use generics there?
d
I thought it might be that. You can use reified generics.
d
yeah the problem is that when it gets compiled the generic type is just an object 😞