Skip to content

Commit

Permalink
Update Ktor to 3.0.3 (#2066)
Browse files Browse the repository at this point in the history
### 📝 Description
Updated Ktor and updated failing tests and fixed compile issues
resulting from the update.
Also updated some libraries. 

### 🔗 Related Issues
#2037

---------

Co-authored-by: TheDome0 <[email protected]>
  • Loading branch information
timemanx and TheDome0 authored Jan 9, 2025
1 parent f1a8603 commit 835d680
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import io.ktor.server.application.Application
import io.ktor.server.application.install
import io.ktor.server.plugins.cors.routing.CORS
import io.ktor.server.plugins.statuspages.StatusPages
import io.ktor.server.routing.Routing
import io.ktor.server.routing.routing
import io.ktor.server.websocket.WebSockets
import io.ktor.server.websocket.pingPeriod
import java.time.Duration
import kotlin.time.Duration.Companion.seconds

fun Application.graphQLModule() {
install(WebSockets) {
pingPeriod = Duration.ofSeconds(1)
pingPeriod = 1.seconds
contentConverter = JacksonWebsocketContentConverter()
}
install(StatusPages) {
Expand Down Expand Up @@ -78,7 +78,7 @@ fun Application.graphQLModule() {
contextFactory = CustomGraphQLContextFactory()
}
}
install(Routing) {
routing {
graphQLGetRoute()
graphQLPostRoute()
graphQLSubscriptionsRoute()
Expand Down
22 changes: 11 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[versions]
android-plugin = "8.5.0"
classgraph = "4.8.174"
dataloader = "3.3.0"
federation = "5.1.0"
graphql-java = "22.1"
dataloader = "3.4.0"
federation = "5.2.0"
graphql-java = "22.3"
graalvm = "0.10.2"
jackson = "2.17.1"
# kotlin version has to match the compile-testing compiler version
kotlin = "2.0.0"
kotlinx-benchmark = "0.4.11"
kotlinx-coroutines = "1.8.1"
kotlinx-benchmark = "0.4.13"
kotlinx-coroutines = "1.9.0"
# TODO kotlin 1.9 upgrade: fix GraphQLTestUtils and GenerateKotlinxClientIT
kotlinx-serialization = "1.6.3"
ktor = "2.3.12"
ktor = "3.0.3"
fastjson2 = "2.0.53"
maven-plugin-annotation = "3.13.1"
maven-plugin-api = "3.9.8"
Expand All @@ -33,16 +33,16 @@ compile-testing = "0.5.1"
icu = "75.1"
junit = "5.10.2"
logback = "1.5.6"
mockk = "1.13.11"
mockk = "1.13.13"
rxjava = "3.1.8"
wiremock = "3.7.0"

# plugins
detekt = "1.23.6"
dokka = "1.9.20"
detekt = "1.23.7"
dokka = "2.0.0"
jacoco = "0.8.12"
ktlint-core = "1.3.0"
ktlint-plugin = "12.1.1"
ktlint-core = "1.5.0"
ktlint-plugin = "12.1.2"
maven-plugin-development = "0.4.3"
nexus-publish-plugin = "2.0.0"
plugin-publish = "1.2.1"
Expand Down
2 changes: 1 addition & 1 deletion integration/graalvm/ktor-graalvm-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ graalvmNative {
binaries {
named("main") {
verbose.set(true)
buildArgs.add("--initialize-at-build-time=io.ktor,kotlin,ch.qos.logback,org.slf4j")
buildArgs.add("--initialize-at-build-time=io.ktor,kotlin,kotlinx.io,ch.qos.logback,org.slf4j")
buildArgs.add("-H:+ReportExceptionStackTraces")
jvmArgs("-Xmx6g")
}
Expand Down
2 changes: 1 addition & 1 deletion integration/graalvm/maven-graalvm-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<configuration>
<verbose>true</verbose>
<buildArgs>
<arg>--initialize-at-build-time=io.ktor,kotlin,ch.qos.logback,org.slf4j</arg>
<arg>--initialize-at-build-time=io.ktor,kotlin,kotlinx.io,ch.qos.logback,org.slf4j</arg>
<arg>-H:+ReportExceptionStackTraces</arg>
</buildArgs>
<jvmArgs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.Routing
import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
Expand All @@ -20,7 +17,6 @@ fun Application.graphQLModule() {
val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
val ktorGraphQLServer: KtorGraphQLServer = KtorGraphQLServer(jacksonObjectMapper)

install(Routing)
routing {
post("graphql") {
val result = ktorGraphQLServer.execute(call.request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class CustomScalarKotlinxTests {

@Test
fun `verify custom scalars are correctly serialized and deserialized`() {
val engine = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
val embeddedServer = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
try {
engine.start()
embeddedServer.start()
runBlocking {
val port = engine.resolvedConnectors().first().port
val port = embeddedServer.engine.resolvedConnectors().first().port
val client = GraphQLKtorClient(url = URL("http://localhost:$port/graphql"))

val undefinedLocaleQuery = LocaleQuery(variables = LocaleQuery.Variables())
Expand All @@ -52,17 +52,17 @@ class CustomScalarKotlinxTests {
assertEquals(ULocale.CANADA, localeResult.data?.localeQuery)
}
} finally {
engine.stop(1000, 1000)
embeddedServer.stop(1000, 1000)
}
}

@Test
fun `verify undefined optionals are correctly serialized and deserialized`() {
val engine = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
val embeddedServer = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
try {
engine.start()
embeddedServer.start()
runBlocking {
val port = engine.resolvedConnectors().first().port
val port = embeddedServer.engine.resolvedConnectors().first().port
val client = GraphQLKtorClient(url = URL("http://localhost:$port/graphql"))

val undefinedWrapperQuery = OptionalScalarQuery(variables = OptionalScalarQuery.Variables())
Expand Down Expand Up @@ -97,15 +97,15 @@ class CustomScalarKotlinxTests {
assertEquals(0, defaultResult.optionalUUIDList?.size)
}
} finally {
engine.stop(1000, 1000)
embeddedServer.stop(1000, 1000)
}
}

@Test
fun `verify null optionals are correctly serialized and deserialized`() {
val engine = embeddedServer(CIO, port = 8080, module = Application::graphQLModule)
val embeddedServer = embeddedServer(CIO, port = 8080, module = Application::graphQLModule)
try {
engine.start()
embeddedServer.start()
runBlocking {
val client = GraphQLKtorClient(url = URL("http://localhost:8080/graphql"))

Expand Down Expand Up @@ -142,15 +142,15 @@ class CustomScalarKotlinxTests {
assertNull(nullResult.optionalUUIDList)
}
} finally {
engine.stop(1000, 1000)
embeddedServer.stop(1000, 1000)
}
}

@Test
fun `verify defined optionals are correctly serialized and deserialized`() {
val engine = embeddedServer(CIO, port = 8080, module = Application::graphQLModule)
val embeddedServer = embeddedServer(CIO, port = 8080, module = Application::graphQLModule)
try {
engine.start()
embeddedServer.start()
runBlocking {
val client = GraphQLKtorClient(url = URL("http://localhost:8080/graphql"))

Expand Down Expand Up @@ -187,15 +187,15 @@ class CustomScalarKotlinxTests {
assertEquals(randomUUID, result.optionalUUIDList?.get(0))
}
} finally {
engine.stop(1000, 1000)
embeddedServer.stop(1000, 1000)
}
}

@Test
fun `verify serialization and deserialization of required type`() {
val engine = embeddedServer(CIO, port = 8080, module = Application::graphQLModule)
val embeddedServer = embeddedServer(CIO, port = 8080, module = Application::graphQLModule)
try {
engine.start()
embeddedServer.start()
runBlocking {
val client = GraphQLKtorClient(url = URL("http://localhost:8080/graphql"))

Expand Down Expand Up @@ -232,7 +232,7 @@ class CustomScalarKotlinxTests {
assertEquals(wrapper.requiredUUIDList[0], result.requiredUUIDList[0])
}
} finally {
engine.stop(1000, 1000)
embeddedServer.stop(1000, 1000)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.Routing
import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
Expand All @@ -20,7 +17,6 @@ fun Application.graphQLModule() {
val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
val ktorGraphQLServer: KtorGraphQLServer = KtorGraphQLServer(jacksonObjectMapper)

install(Routing)
routing {
post("graphql") {
val result = ktorGraphQLServer.execute(call.request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import kotlin.test.assertNull
class ApplicationTest {
@Test
fun `verify ktor client can execute queries`() {
val engine = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
val embeddedServer = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
try {
engine.start()
embeddedServer.start()
runBlocking {
val port = engine.resolvedConnectors().first().port
val port = embeddedServer.engine.resolvedConnectors().first().port
val client = GraphQLKtorClient(url = URL("http://localhost:$port/graphql"))

val result = client.execute(TestQuery(variables = TestQuery.Variables(name = OptionalInput.Defined("junit"))))
Expand All @@ -40,7 +40,7 @@ class ApplicationTest {
assertEquals(ExampleEnum.ONE.name, testObject.choice.name)
}
} finally {
engine.stop(1000, 1000)
embeddedServer.stop(1000, 1000)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.Routing
import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
Expand All @@ -20,7 +17,6 @@ fun Application.graphQLModule() {
val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
val ktorGraphQLServer: KtorGraphQLServer = KtorGraphQLServer(jacksonObjectMapper)

install(Routing)
routing {
post("graphql") {
val result = ktorGraphQLServer.execute(call.request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import kotlin.test.assertNull
class ApplicationTest {
@Test
fun `verify ktor client can execute queries`() {
val engine = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
val embeddedServer = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
try {
engine.start()
embeddedServer.start()
runBlocking {
val port = engine.resolvedConnectors().first().port
val port = embeddedServer.engine.resolvedConnectors().first().port
val client = GraphQLKtorClient(url = URL("http://localhost:$port/graphql"))

val result = client.execute(TestQuery(variables = TestQuery.Variables(name = OptionalInput.Defined("junit"))))
Expand All @@ -40,7 +40,7 @@ class ApplicationTest {
assertEquals(ExampleEnum.ONE.name, testObject.choice.name)
}
} finally {
engine.stop(1000, 1000)
embeddedServer.stop(1000, 1000)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.Routing
import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
Expand All @@ -20,7 +17,6 @@ fun Application.graphQLModule() {
val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
val ktorGraphQLServer: KtorGraphQLServer = KtorGraphQLServer(jacksonObjectMapper)

install(Routing)
routing {
post("graphql") {
val result = ktorGraphQLServer.execute(call.request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class PolymorphicKotlinxTests {

@Test
fun `verify polymorphic queries are correctly serialized and deserialized`() {
val engine = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
val embeddedServer = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
try {
engine.start()
embeddedServer.start()
runBlocking {
val port = engine.resolvedConnectors().first().port
val port = embeddedServer.engine.resolvedConnectors().first().port
val client = GraphQLKtorClient(url = URL("http://localhost:$port/graphql"))

val query = CompletePolymorphicQuery(variables = CompletePolymorphicQuery.Variables(input = "foo"))
Expand All @@ -46,16 +46,16 @@ class PolymorphicKotlinxTests {
assertNull(nullResponse.data?.unionQuery)
}
} finally {
engine.stop(1000, 1000)
embeddedServer.stop(1000, 1000)
}
}

@OptIn(ExperimentalSerializationApi::class)
@Test
fun `verify polymorphic queries fallbacks are correctly serialized and deserialized`() {
val engine = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
val embeddedServer = embeddedServer(CIO, port = 0, module = Application::graphQLModule)
try {
engine.start()
embeddedServer.start()
runBlocking {
// need to register fallback logic
val serializerWithFallback = GraphQLClientKotlinxSerializer(jsonBuilder = {
Expand All @@ -68,7 +68,7 @@ class PolymorphicKotlinxTests {
}
}
})
val port = engine.resolvedConnectors().first().port
val port = embeddedServer.engine.resolvedConnectors().first().port
val client = GraphQLKtorClient(url = URL("http://localhost:$port/graphql"), serializer = serializerWithFallback)

val fallbackQuery = PartialPolymorphicQuery(variables = PartialPolymorphicQuery.Variables(input = "bar"))
Expand All @@ -79,7 +79,7 @@ class PolymorphicKotlinxTests {
assertTrue(unionResult is DefaultBasicUnionImplementation)
}
} finally {
engine.stop(1000, 1000)
embeddedServer.stop(1000, 1000)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.expediagroup.graphql.server.ktor.graphQLGetRoute
import com.expediagroup.graphql.server.ktor.graphQLPostRoute
import io.ktor.server.application.Application
import io.ktor.server.application.install
import io.ktor.server.routing.Routing
import io.ktor.server.routing.routing

fun Application.graphQLModule() {
install(GraphQL) {
Expand All @@ -31,7 +31,7 @@ fun Application.graphQLModule() {
)
}
}
install(Routing) {
routing {
graphQLGetRoute()
graphQLPostRoute()
}
Expand Down
Loading

0 comments on commit 835d680

Please sign in to comment.