jvmMain.com.apollographql.apollo3.api.-Data.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-api-jvm Show documentation
Show all versions of apollo-api-jvm Show documentation
Apollo GraphQL API classes
package com.apollographql.apollo3.api
import com.apollographql.apollo3.annotations.ApolloExperimental
import com.apollographql.apollo3.api.json.JsonWriter
import com.apollographql.apollo3.api.json.buildJsonString
private fun Operation.Data.adapter(): Adapter {
val name = this::class.java.name
val operationQualifiedName = name.removeSuffix("${'$'}Data")
val operationName = operationQualifiedName.substringAfterLast(".")
val packageName = operationQualifiedName.substringBeforeLast(".")
val adapterName = "$packageName.adapter.${operationName}_ResponseAdapter${'$'}Data"
val clazz = Class.forName(adapterName)
val field = clazz.getDeclaredField("INSTANCE")
@Suppress("UNCHECKED_CAST")
val adapter = field.get(null) as Adapter
return adapter.obj()
}
actual fun Operation.Data.toJson(jsonWriter: JsonWriter, customScalarAdapters: CustomScalarAdapters) {
adapter().toJson(jsonWriter, customScalarAdapters, this)
}
@ApolloExperimental
fun Operation.Data.toJsonString(customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, indent: String? = null): String {
return buildJsonString(indent) {
toJson(this, customScalarAdapters)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy