-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Ktor to 3.0.3 #2066
base: master
Are you sure you want to change the base?
Update Ktor to 3.0.3 #2066
Conversation
… Type for invalid POST payload
every { application } returns mockk(relaxed = true) { | ||
every { receivePipeline } returns ApplicationReceivePipeline() | ||
} | ||
coEvery { receiveNullable<Any>(any()) } answers { callOriginal() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
receiveNullable()
(which is called from ApplicationCall.receive()
in KtorGraphQLRequestParser.parsePostRequest()
) is now an instance method instead of an extension function which is why ApplicationCall.receive()
returns null when using a mock.
Using callOriginal()
calls the instance method instead.
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
embeddedServer()
now returns an EmbeddedServer
which contains the ApplicationEngine
.
https://ktor.io/docs/migrating-3.html#EmbeddedServer
|
||
fun Application.graphQLModule() { | ||
install(WebSockets) { | ||
pingPeriod = Duration.ofSeconds(1) | ||
pingPeriod = 1.seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Websockets plugin now uses kotlin.time
.
https://github.com/ktorio/ktor/blob/main/CHANGELOG.md#improvements-3
https://youtrack.jetbrains.com/issue/KTOR-7446
|
||
private fun testModule(block: suspend io.ktor.server.testing.ApplicationTestBuilder.() -> kotlin.Unit) = testApplication { | ||
environment { | ||
config = ApplicationConfig(("application.conf")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modules need to be explicitly loaded.
https://ktor.io/docs/migrating-3.html#test-module-loading
…nsformContentToTypeException instead
@@ -61,6 +62,8 @@ open class KtorGraphQLRequestParser( | |||
|
|||
private suspend fun parsePostRequest(request: ApplicationRequest): GraphQLServerRequest? = try { | |||
request.call.receive() | |||
} catch (e: CannotTransformContentToTypeException) { | |||
throw e | |||
} catch (e: IOException) { | |||
throw IllegalStateException("Invalid HTTP request - unable to parse GraphQL request from POST payload", e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed InvalidPayloadException
that was added in the commit 30c32b9.
Instead, CannotTransformContentToTypeException
can be re-thrown to maintain current behaviour (and also pass this test).
The reason being that ContentTransformationException
(super class of CannotTransformContentToTypeException
) derives from IOException
in Ktor 3.x which results in the exception being caught here in parsePostRequest()
instead of being passed on in the chain to Ktor's default interceptor (which is where the 415 error response is returned).
Re-throwing this exception allows Ktor's internal interceptor to catch it and maintain existing behaviour.
Reference: ContentTransformationException
in 2.3.13 vs 3.x.
An alternative to this solution could be to instead throw UnsupportedMediaTypeException. However, that would also require handling it in GraphQLStatusPages.
📝 Description
Updated Ktor and updated failing tests and fixed compile issues resulting from the update.
Also updated some libraries.
🔗 Related Issues
#2037