From 5d9bd6f030c0fed8731dafa6b74b29bb9fbac57a Mon Sep 17 00:00:00 2001 From: ronjunevaldoz Date: Sun, 29 Sep 2024 00:07:05 +0800 Subject: [PATCH] Upgrade to ktor version 3 --- gradle/libs.versions.toml | 2 +- .../com/expediagroup/graphql/server/ktor/GraphQLRoutes.kt | 6 +++--- .../expediagroup/graphql/server/ktor/GraphQLPluginTest.kt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 38e228d180..6670ac5fc2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,7 +12,7 @@ kotlinx-benchmark = "0.4.11" kotlinx-coroutines = "1.8.1" # TODO kotlin 1.9 upgrade: fix GraphQLTestUtils and GenerateKotlinxClientIT kotlinx-serialization = "1.6.3" -ktor = "2.3.12" +ktor = "3.0.0-rc-1" maven-plugin-annotation = "3.13.1" maven-plugin-api = "3.9.8" maven-project = "2.2.1" diff --git a/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/GraphQLRoutes.kt b/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/GraphQLRoutes.kt index 7ec6e232f2..c9761e98fa 100644 --- a/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/GraphQLRoutes.kt +++ b/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/GraphQLRoutes.kt @@ -115,11 +115,11 @@ fun Route.graphiQLRoute( graphQLEndpoint: String = "graphql", subscriptionsEndpoint: String = "subscriptions", ): Route { - val contextPath = this.environment?.rootPath + val contextPath = this.application.rootPath val graphiQL = GraphQL::class.java.classLoader.getResourceAsStream("graphql-graphiql.html")?.bufferedReader()?.use { reader -> reader.readText() - .replace("\${graphQLEndpoint}", if (contextPath.isNullOrBlank()) graphQLEndpoint else "$contextPath/$graphQLEndpoint") - .replace("\${subscriptionsEndpoint}", if (contextPath.isNullOrBlank()) subscriptionsEndpoint else "$contextPath/$subscriptionsEndpoint") + .replace("\${graphQLEndpoint}", if (contextPath.isBlank()) graphQLEndpoint else "$contextPath/$graphQLEndpoint") + .replace("\${subscriptionsEndpoint}", if (contextPath.isBlank()) subscriptionsEndpoint else "$contextPath/$subscriptionsEndpoint") } ?: throw IllegalStateException("Unable to load GraphiQL") return get(endpoint) { call.respondText(graphiQL, ContentType.Text.Html) diff --git a/servers/graphql-kotlin-ktor-server/src/test/kotlin/com/expediagroup/graphql/server/ktor/GraphQLPluginTest.kt b/servers/graphql-kotlin-ktor-server/src/test/kotlin/com/expediagroup/graphql/server/ktor/GraphQLPluginTest.kt index 510bb689ae..1883f2aa00 100644 --- a/servers/graphql-kotlin-ktor-server/src/test/kotlin/com/expediagroup/graphql/server/ktor/GraphQLPluginTest.kt +++ b/servers/graphql-kotlin-ktor-server/src/test/kotlin/com/expediagroup/graphql/server/ktor/GraphQLPluginTest.kt @@ -37,7 +37,7 @@ import io.ktor.serialization.jackson.jackson import io.ktor.server.application.Application import io.ktor.server.application.install import io.ktor.server.plugins.statuspages.StatusPages -import io.ktor.server.routing.Routing +import io.ktor.server.routing.* import io.ktor.server.testing.testApplication import io.ktor.websocket.Frame import io.ktor.websocket.readText @@ -260,7 +260,7 @@ fun Application.testGraphQLModule() { } } install(io.ktor.server.websocket.WebSockets) - install(Routing) { + routing { graphQLGetRoute() graphQLPostRoute() graphQLSubscriptionsRoute()