Result JSON cut off
KuschL opened this issue · 6 comments
The JSON Response of my QueryResolver cuts off the text if I load emojis in the text-field. I think it's an encoding problem but I don't know how to solve it. I can recreate the issue with following code:
// Message.kt
@Document
data class Message(
var text: String,
var sender: User,
var createdAt: Date = Date(),
var chatId: String
) {
@Id
@NotNull
lateinit var id: String
}// MessageQueryResolver.kt
@Component
class ChatQueryResolver(
private val chatRepository: ChatRepository,
private val messageRepository: MessageRepository
) : GraphQLQueryResolver {
fun getMessages(chatId: String, createdAt: Date?, size: Int?): List<Message>? {
val chat = chatRepository.findById(chatId).orElseThrow { throw RuntimeException("Chat not found") }
val pageable: Pageable = PageRequest.of(0, size ?: 50)
return messageRepository.findAllByChatIdAndCreatedAtLessThanOrderByCreatedAtDesc(
pageable,
chatId,
createdAt ?: Date()
).toList()
}
}If I query getMessages the result JSON is cut off, so it will be invalid:
{
getMessages(chatId: "global", size:1) {
id
text
}
}"{\"data\":{\"getMessages\":[{\"id\":\"5dea59a33b59764933d133f6\",\"text\":\"this is an test with an emoji... 🤷♂"I'm using the following versions of Spring Boot and GraphQL Libraries:
plugins {
id("org.springframework.boot") version "2.2.1.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
kotlin("jvm") version "1.3.50"
kotlin("plugin.spring") version "1.3.50"
}
// ...
dependencies {
implementation("io.reactivex.rxjava2:rxjava:2.2.3")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
implementation("com.graphql-java-kickstart:graphql-spring-boot-starter:6.0.0")
implementation("com.graphql-java-kickstart:graphiql-spring-boot-starter:6.0.0")
// ...Addition: It also fails to create correct JSON if characters like 'äöü' appear in the text-field.
I also got this issue when the output json text contains Thai character. I spent huge time try to figure out and found that it isn't the problem when using 5.10.0 version.
If result data contains non latin characters (russian in my case) the JSON response is cropped, but we can see some string values in right encoding.
Theres already a pull request to fix this issue. So we jus have to wait until it is merged.
see: graphql-java-kickstart/graphql-java-servlet#219
To fix it now, you can import the fixed version of graphql-java-servlet yourself:
// build.gradle.kt
// ...
repositories {
// ...
maven { url = uri("http://oss.jfrog.org/artifactory/oss-snapshot-local") }
}
// ...
dependencies {
// ...
implementation("com.graphql-java-kickstart:graphql-java-servlet:9.0.1")
// ...Hello @KuschL I see that the PR 219 was merged.
How long it can take to see the fix in this package?
Just released version 6.0.1 of this package that fixes this issue.