https://kotlinlang.org logo
#graphql-kotlin
Title
# graphql-kotlin
e

edwinRNDR

07/16/2021, 12:04 PM
Thinking this may be more a ktor problem. I made a horrible work-around:
Copy code
class KtorGraphQLRequestParser(
    private val mapper: ObjectMapper
) : GraphQLRequestParser<ApplicationRequest> {
    @Suppress("BlockingMethodInNonBlockingContext")
    override suspend fun parseRequest(request: ApplicationRequest): GraphQLServerRequest = try {
        val rawRequest = request.call.receiveText()
        val encoded = rawRequest.toByteArray(Charsets.ISO_8859_1)
        val decoded = String(encoded, Charsets.UTF_8)
        mapper.readValue(decoded, GraphQLServerRequest::class.java)
    } catch (e: IOException) {
        throw IOException("Unable to parse GraphQL payload.")
    }
}
s

Shane Myrick

07/16/2021, 3:04 PM
That is what you have to do if you want to use ISO 8859-1 content: https://github.com/FasterXML/jackson-core/issues/222
JSON does NOT allow use of ISO-8859-1 as per specification; only UTF-8, UTF-16 and UTF-32 are supported
e

edwinRNDR

07/16/2021, 3:53 PM
the problem is that the content is in utf-8 but ktor somehow assumes it is in iso-8859-1.
s

Shane Myrick

07/16/2021, 4:05 PM
So with your current setup is it properly decoding and sending into to the functions or do you still have issues?
e

edwinRNDR

07/16/2021, 4:09 PM
the work-around fixes everything. I am just wondering if I failed to configure something properly
s

Shane Myrick

07/16/2021, 5:38 PM
That sounds like a Ktor specific issue but that is how you would properly parse a custom request format. Then the schema generator should get a valid argument from that request
3 Views