我有2个查询具有相同的类型
的数据
我尝试像这样将findOrderByOid
插入到[FindOrderByRestaurantId]
中
var orderListData: ArrayList<FindOrderByRestaurantIdQuery.FindOrderByRestaurantId?> = ArrayList()
fun getOrderList(){
scope.launch {
apolloBuilder.apolloBuild().query(
FindOrderByRestaurantIdQuery(
id = "1"
)
).execute().apply {
orderListData = data?.findOrderByRestaurantId?.toCollection(ArrayList()) ?: ArrayList()
}
}
}
fun getOrderDetail(){
scope.launch {
apolloBuilder.apolloBuild().query(
FindOrderByOidQuery(
oid = "15"
)
).execute().apply {
data?.findOrderByOid?.let {
orderListData.add(it)
}
}
}
}
字符串
但是,
Type mismatch.
Required: FindOrderByRestaurantIdQuery.FindOrderByRestaurantId?
Found: FindOrderByOidQuery.FindOrderByOid
型
我不能创建新的data class
,然后逐个解析,因为OrderResult
有近百个变量。
我如何得到返回响应为OrderResult
??
这里我gradle:
plugins {
id 'com.android.application' version '8.1.2' apply false
id 'org.jetbrains.kotlin.android' version "1.9.0" apply false
id 'com.apollographql.apollo3' version '3.8.2' apply false
id 'org.jetbrains.kotlin.jvm' version '1.9.10' apply false
...
}
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.apollographql.apollo3'
...
}
android {
...
compileSdk 34
defaultConfig {
...
minSdk 21
targetSdk 34
...
}
compileOptions {
sourceCompatibility 17
targetCompatibility 17
}
kotlinOptions {
jvmTarget = '17'
}
}
apollo {
service("myapp") {
packageName.set("com.myapp.app")
// codegenModels.set("responseBased")
introspection {
endpointUrl.set("https://endpoint.com/data/")
schemaFile.set(file("src/main/graphql/sg/com/myapp/app/schema.graphqls"))
}
customTypeMapping = [
"Date" : "kotlin.String",
"DateTime": "kotlin.String",
"Time" : "kotlin.String",
"BigInt" : "kotlin.Long",
"Double" : "kotlin.Double"
]
}
}
dependencies {
...
implementation 'com.apollographql.apollo3:apollo-runtime:3.8.2'
implementation 'com.apollographql.apollo3:apollo-api:3.8.2'
...
}
的字符串
如果我错过了什么,让我知道
谢谢
1条答案
按热度按时间6tqwzwtp1#
在我将问题插入
apollo-kotlin
后,我得到了答案将字段graphql设置为片段
字符串
然后在Kotlin中,像这样设置响应
型