Hi all, I'm learning Kotlin + Ktor + Graphql by f...
# getting-started
r
Hi all, I'm learning Kotlin + Ktor + Graphql by following this tutorial. However, when I run the server and visit http://localhost:8080/graphql I do not see the graphql playground 🤔 Here's what I did so far: • created the project using the project builder on ktor.io • added the kgraphql_version in gradle.properties • updated the build.gradle.kts with the line mentioned in the tutorial • in the tutorial
src/Application.kt
is mentioned but my automatically generated
Application.kt
file is under
src/main/kotlin/com.ryanzidago/Application.kt
🤔 Here's the content of my
Application.kt
Copy code
package com.ryanzidago

import io.ktor.server.engine.*
import io.ktor.server.netty.*
import com.ryanzidago.plugins.*

import io.ktor.application.Application
import io.ktor.application.install
import com.apurebase.kgraphql.GraphQL

fun main() {
    embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
        configureRouting()
    }.start(wait = true)
}
fun Application.module(testing: Boolean = false) {
    install(GraphQL) {
        playground = true
        schema {
            query("hello") {
                resolver { -> "World" }
            }
        }
    }
}
Intellij tells me that there is a problem with the
install
(Not enough information to infer type variable B) and
playground
(Variable expected) but I cannot figure out what is wrong 🤔 When I type
gradle --version
in my project root I get the following output:
Copy code
ariviv 
❯ gradle --version

------------------------------------------------------------
Gradle 7.3.3
------------------------------------------------------------

Build time:   2021-12-22 12:37:54 UTC
Revision:     6f556c80f945dc54b50e0be633da6c62dbe8dc71

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.1 (Oracle Corporation 17.0.1+12-39)
OS:           Linux 5.4.0-94-generic amd64
Any tips?
d
Does the app start? In general
/graphql
would be used to accept queries (through POST or GET). Unsure how
kgraphql
does the routing but I've often seen (and we do it in
graphql-kotlin
) the specific
/playground
routes (or
/graphiql
,
/voyager
etc) for the tooling.
r
Yes the app starts:
Here, the author specifically mentioned http://localhost:8080/graphql as the endpoint to use in order to see the playground 🤔
v
Regarding the errors in IntelliJ, try to refresh the Gradle project. This shows that you have unsynced changes:
So you probably just don't have the graph ql library in IntelliJ which is why it cannot import and then also not use it
d
this ⬆️
r
Alright, I did it and it seems that now, the error is gone. However, I still can't visit the endpoint 🤔
(I've restarted the server in the meantime)
d
not familiar with that lib so won't be much help based on https://github.com/aPureBase/KGraphQL/blob/main/kgraphql-ktor/src/main/kotlin/com/apurebase/kgraphql/KtorFeature.kt#L66 it does use same
/graphql
endpoint for surfacing
playground
using GET requests (which does not follow best practices defined in https://graphql.org/learn/serving-over-http/)
v
Yeah, that didn't change anything but what IntelliJ sees when displaying to you.
Application.module
color-wise looks unused, should that be called somewhere?
I have no idea though about ktor or kgraphql
d
we (I am one of the maintainers of
graphql-kotlin
) don't have a tutorial for ktor (there is one for Spring) but there is an example app -> https://github.com/ExpediaGroup/graphql-kotlin/tree/master/examples/server/ktor-server maybe that can be of some help
👀 1
v
The tutorial says add lines to
module
, but I guess this just does not fit the generated template anymore, also because the path is differently and that you simply added the whole function
r
Thanks @Dariusz Kuc I'll definitely look into it.
@Vampire yeah the tuto does not fit the generated template anymore; but I'm a bit at loss as to how to configure kgraphql with Ktor 🤔
v
Ask them? Especially to update the outdated tutorial?
👍 1
r
I need to get this done for a take home task 🤷 I guess by the time they'll update the docs it might be too late 😅
v
But they might answer faster than they update the docs. It seems here you will not get help as noone (at least active right now) knows what that is about.
r
Alright thank you very much for your time 🙏
Okay so apparently, I needed to not get rid of the
configureRouting()
call in my
Application.module
function. Now it works!
👌 1
Hopefully, this will prevent someone in the future to have to spent many hours like I did on this issue 😅
124 Views