Skip to content

Commit

Permalink
adding checks for json end_document in http batching interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
duzinkie authored and martinbonnin committed Jun 14, 2024
1 parent 8115e51 commit 0d385dc
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.apollographql.apollo3.api.http.HttpResponse
import com.apollographql.apollo3.api.http.valueOf
import com.apollographql.apollo3.api.json.BufferedSinkJsonWriter
import com.apollographql.apollo3.api.json.BufferedSourceJsonReader
import com.apollographql.apollo3.api.json.JsonReader
import com.apollographql.apollo3.api.json.buildJsonByteString
import com.apollographql.apollo3.api.json.writeArray
import com.apollographql.apollo3.exception.ApolloException
Expand All @@ -30,6 +31,7 @@ import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import okio.Buffer
import okio.BufferedSink
import okio.use
import kotlin.jvm.JvmOverloads
import kotlin.jvm.JvmStatic

Expand Down Expand Up @@ -180,8 +182,14 @@ class BatchingHttpInterceptor @JvmOverloads constructor(
}
val responseBody = response.body ?: throw DefaultApolloException("null body when executing batched query")

// TODO: this is most likely going to transform BigNumbers into strings, not sure how much of an issue that is
val list = AnyAdapter.fromJson(BufferedSourceJsonReader(responseBody), CustomScalarAdapters.Empty)
val list = BufferedSourceJsonReader(responseBody).use { jsonReader ->
// TODO: this is most likely going to transform BigNumbers into strings, not sure how much of an issue that is
AnyAdapter.fromJson(jsonReader, CustomScalarAdapters.Empty).also {
if (jsonReader.peek() != JsonReader.Token.END_DOCUMENT) {
println("Apollo: extra tokens after payload")
}
}
}
if (list !is List<*>) throw DefaultApolloException("batched query response is not a list when executing batched query")

if (list.size != pending.size) {
Expand Down

0 comments on commit 0d385dc

Please sign in to comment.