commonMain.com.apollographql.apollo.api.internal.SimpleOperationResponseParser.kt Maven / Gradle / Ivy
package com.apollographql.apollo.api.internal
import com.apollographql.apollo.api.Error
import com.apollographql.apollo.api.Operation
import com.apollographql.apollo.api.Response
import com.apollographql.apollo.api.ScalarTypeAdapters
import com.apollographql.apollo.api.internal.json.BufferedSourceJsonReader
import com.apollographql.apollo.api.internal.json.ResponseJsonStreamReader
import com.apollographql.apollo.api.internal.json.use
import okio.BufferedSource
import okio.IOException
import kotlin.jvm.JvmStatic
object SimpleOperationResponseParser {
@JvmStatic
@Throws(IOException::class)
fun parse(
source: BufferedSource,
operation: Operation,
scalarTypeAdapters: ScalarTypeAdapters
): Response {
return BufferedSourceJsonReader(source).use { jsonReader ->
jsonReader.beginObject()
val response = ResponseJsonStreamReader(jsonReader).toMap().orEmpty()
parse(response, operation, scalarTypeAdapters)
}
}
@Suppress("UNCHECKED_CAST")
private fun parse(
response: Map,
operation: Operation,
scalarTypeAdapters: ScalarTypeAdapters
): Response {
val responseData = response["data"] as? Map
val data = responseData?.let {
val responseReader = SimpleResponseReader(it, operation.variables(), scalarTypeAdapters)
operation.responseFieldMapper().map(responseReader)
}
val responseErrors = response["errors"] as? List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy