https://kotlinlang.org logo
#ktor
Title
# ktor
a

Adam Firen

12/01/2020, 6:37 PM
I have joined the channel to have a chat about graphql support for ktor, would this be the right place to open a thread about it?
r

rudolf.hladik

12/01/2020, 6:59 PM
I think it is a good place to start. I have tried GraphQl multiplatform and I was able to run the plugin for generation of models and queries, but I was unable to run them on iOS. So I’ve tried to run them manually with Ktor and it worked. here is a snippet
Copy code
suspend fun getLaunches(): List<GetLaunchesQuery.Launch> {
        val query = GetLaunchesQuery()
        val request = query.composeRequestBody()
            .toByteArray()
        val response = httpClient.request<HttpResponse> {
            body = request
            method = <http://HttpMethod.Post|HttpMethod.Post>
            url(graphQlurl)
            header("Accept", "application/json")
            header("Content-Type", "application/json")
        }
        val responseData = query.parse(response.readBytes().toByteString())
return responseData
            .data?.launches?.launches
            ?.mapNotNull { it }
            .orEmpty()
}
a

Adam Firen

12/01/2020, 7:00 PM
what library did you use?
r

rudolf.hladik

12/01/2020, 7:01 PM
just
com.apollographql.apollo:apollo-api:2.4.5
you also need to use gradle plugin
Copy code
id("com.apollographql.apollo")
from
Copy code
classpath("com.apollographql.apollo:apollo-gradle-plugin:2.4.5")
a

Adam Firen

12/01/2020, 7:26 PM
that’s also interesting, still another approach to the issue 🙂
m

manlan

12/05/2020, 6:08 PM
@Adam Firen So when you say Graphql support for Ktor, you mean on the client side?
a

Adam Firen

12/05/2020, 6:08 PM
Server side
m

manlan

12/05/2020, 6:11 PM
Hmmm there's no official support for Graphql, but there are libraries like #kgraphql #graphql-kotlin which can you help you with creating a Graphql endpoint with Ktor
a

Adam Firen

12/05/2020, 6:13 PM
Yeah I am aware of them. I was more interested if there is any ktor creators iniciative or they want to leave it to the community and the projects you have mentioned
👍🏼 1