Proceesing 2 queries graphql response that have same type into array

Proceesing 2 queries graphql response that have same type into array


0

I have 2 queries that have same type

Proceesing 2 queries graphql response that have same type into array

I tried to insert findOrderByOid into [FindOrderByRestaurantId] like this

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)
                }
            }
        }
    }

but getting error

Type mismatch.
Required: FindOrderByRestaurantIdQuery.FindOrderByRestaurantId?
Found: FindOrderByOidQuery.FindOrderByOid

I cannot making new data class then parsing one by one because OrderResult has almost hundred variables.

How I can get return response as OrderResult??

Here my 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'
    ...
}

If I missing somthing, let me know

Thanks


Load 4 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *