Apollo-android: Why I am getting 'ApolloParseException' after upgrading from 1.0.0-alpha to 1.0.0 ?

Created on 31 Dec 2020  路  13Comments  路  Source: apollographql/apollo-android

Hi Team ,

I am currently upgraded an old project's Apollo version from 1.0.0-alpha to 1.0.0 .

After upgrading I am getting this Execption

    com.apollographql.apollo.exception.ApolloParseException: Failed to parse http response
        at com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor.parse(ApolloParseInterceptor.java:101)
        at com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor$1.onResponse(ApolloParseInterceptor.java:53)
        at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$1$1.onResponse(ApolloServerInterceptor.java:106)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:203)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.io.EOFException: End of input
        at com.apollographql.apollo.internal.json.BufferedSourceJsonReader.nextNonWhitespace(BufferedSourceJsonReader.java:946)
        at com.apollographql.apollo.internal.json.BufferedSourceJsonReader.doPeek(BufferedSourceJsonReader.java:332)
        at com.apollographql.apollo.internal.json.BufferedSourceJsonReader.beginObject(BufferedSourceJsonReader.java:169)
        at com.apollographql.apollo.response.OperationResponseParser.parse(OperationResponseParser.java:82)
        at com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor.parse(ApolloParseInterceptor.java:87)
        at com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor$1.onResponse(ApolloParseInterceptor.java:53)聽
        at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$1$1.onResponse(ApolloServerInterceptor.java:106)聽
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:203)聽
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)聽
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)聽
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)聽
        at java.lang.Thread.run(Thread.java:764)聽

But everything was fine till I upgraded . I upgraded to 1.0 stable from alpha because I upgraded Gradle due to Firebase Crashlytics migration .

Apollo alpha thowed build errors in new Gradle . So I upgraded to 1.0 and build success

But after opening the app , I got this exception

The mystery here is =>

The okHTTP logging intercepter printing the response JSON and it valid and correct too.

But Apollo can't parse it

Why apollo can't parse the JSON when it received correctly ?

Limitations
And one Sad thing is , I can't upgrade to latest apollo versions due to using lot of old packages, since old packages incompatible with new Gradle 6+ and apollo latest version needs new Gradle .

Please help me

Info :

Apollo version : : 1.0 (1.0 alpha before)
Gradle build tools: : 3.6.4
Gradle : 5.6.4
Kotlin : : 1.3.72

Sample Query

#Get Profile Details
query GetProfile {
 userAccount {
 result {
 userId
 profileId
 firstName
 lastName
 displayName
 gender
 dateOfBirth
 iosDOB
 email
 userBanStatus
 phoneNumber
 preferredLanguage
 preferredLanguageName
 preferredCurrency
 location
 info
 createdAt
 picture
 country
 loginUserType
 isAddedList
 verification {
 id
 isEmailConfirmed
 isFacebookConnected
 isGoogleConnected
 isIdVerification
 isPhoneVerified
 }
 userData {
 type
 }
 verificationCode
 countryCode
 loginUserType
 isAddedList
 }
 status
 errorMessage
 }
 }

Response (from okhttp logger) :

{
  "data": {
    "userAccount": {
      "__typename": "WholeAccount",
      "result": {
        "__typename": "UserAccount",
        "userId": "2bced470-49b7-11eb-a6aa-89804552bd8c",
        "profileId": 28,
        "firstName": "Ragesh",
        "lastName": "Antony",
        "displayName": "Ragesh Antony",
        "gender": null,
        "dateOfBirth": "6-1993-3",
        "iosDOB": "6-3-1993",
        "email": "[email protected]",
        "userBanStatus": null,
        "phoneNumber": null,
        "preferredLanguage": null,
        "preferredLanguageName": null,
        "preferredCurrency": null,
        "location": null,
        "info": null,
        "createdAt": "1609233662000",
        "picture": "52cd186f3f176cd981a4085887cd019d.jpeg",
        "country": null,
        "loginUserType": "Guest",
        "isAddedList": false,
        "verification": {
          "__typename": "UserVerifiedInfo",
          "id": 28,
          "isEmailConfirmed": true,
          "isFacebookConnected": false,
          "isGoogleConnected": false,
          "isIdVerification": false,
          "isPhoneVerified": false
        },
        "userData": {
          "__typename": "UserType",
          "type": "email"
        },
        "verificationCode": null,
        "countryCode": null
      },
      "status": 200,
      "errorMessage": null
    }
  }
} 

======

Apollo Config Module :

https://gist.github.com/RageshAntony/86686ebb9557698d8569acec6fc04b42

Please help me to resolve this issue

waiting for info

Most helpful comment

Hi Antony! Could you try to make a small isolated, standalone project that reproduces the problem and update Apollo Android there to confirm it's working well in the latest version (2.4.6 as we're speaking) ?

Overall, the path forward there is definitely to update your dependencies and Gradle version so that you can pick up latest fixes in apollo-android but also Gradle and your other dependencies. Apollo Android works Gradle 5.6+, not only Gradle 6+ so maybe that can help.

If upgrading your dependencies is out of the question, you could use apollo-android in a separate library project that uses a recent Gradle as a mitigation. This way, you can keep using Gradle 3.6 in your main project and progressively move your dependencies to Gradle 6 (or more). To do this, you'll have to publish the library project as explained here. That'll add a bit more complexity to your build so I'd recommend updating the dependencies as a first approach but that could be an option if everything else fails.

All 13 comments

Hi Antony! Could you try to make a small isolated, standalone project that reproduces the problem and update Apollo Android there to confirm it's working well in the latest version (2.4.6 as we're speaking) ?

Overall, the path forward there is definitely to update your dependencies and Gradle version so that you can pick up latest fixes in apollo-android but also Gradle and your other dependencies. Apollo Android works Gradle 5.6+, not only Gradle 6+ so maybe that can help.

If upgrading your dependencies is out of the question, you could use apollo-android in a separate library project that uses a recent Gradle as a mitigation. This way, you can keep using Gradle 3.6 in your main project and progressively move your dependencies to Gradle 6 (or more). To do this, you'll have to publish the library project as explained here. That'll add a bit more complexity to your build so I'd recommend updating the dependencies as a first approach but that could be an option if everything else fails.

Hi Antony! Could you try to make a small isolated, standalone project that reproduces the problem and update Apollo Android there to confirm it's working well in the latest version (2.4.6 as we're speaking) ?

Overall, the path forward there is definitely to update your dependencies and Gradle version so that you can pick up latest fixes in apollo-android but also Gradle and your other dependencies. Apollo Android works Gradle 5.6+, not only Gradle 6+ so maybe that can help.

If upgrading your dependencies is out of the question, you could use apollo-android in a separate library project that uses a recent Gradle as a mitigation. This way, you can keep using Gradle 3.6 in your main project and progressively move your dependencies to Gradle 6 (or more). To do this, you'll have to publish the library project as explained here. That'll add a bit more complexity to your build so I'd recommend updating the dependencies as a first approach but that could be an option if everything else fails.

Hi Martin Bonnin ,

Thanks very much.

Like you suggested I created a New project and executed the query with Apollo 2.4.6. It's success

So I upgraded Apollo In my main project and fixed other library issues

Now I able to parse queries without problems
Thanks

But one issue occurring

If I set generate Kotlin models to True , I can't build project

I am getting

Can't find symbol <QueryClassName>
Ex : Can't find symbol UserLoginQuery ...

So I have to set generate Kotlin models False ...

Pls help me

Apollo version : : 2.4.6
Gradle build tools: : 4.1.1
Gradle : 6.7.1
Kotlin : : 1.3.72

Thanks very much. Like you suggested I created a New project and executed the query with Apollo 2.4.6. It's success

Nice, glad to hear that !

If I set generate Kotlin models to True , I can't build project

That's unfortunate. Can you copy/paste the full stacktrace?

That's unfortunate. Can you copy/paste the full stacktrace?

Yeah . See here

--> https://gist.github.com/RageshAntony/e973e54861ae8c8e9a345f4adbcd40e2

Gist contains

  1. stack trace
  2. Build Log
  3. ApiHelper.kt for query helper
  4. AppApiHelper.kt for query Rxjava integration + intercepter
  5. kept generated java classes of 3 & 4
  6. Generated Kotlin Query Class
  7. app gradle and project gradle
  8. schema.json
  9. a query. GraphQL file

Version:

Apollo version : : 2.4.6
Gradle build tools: : 4.1.1
Gradle : 6.7.1
Kotlin : : 1.3.72
dagger : 2.24

points :

  1. In the ApiHelper.kt , the IDE showing 'unable to resolve Builder'.
  2. The Query classes are generated in Kotlin and I able to open the Kotlin class , when I click cmd/ctrl + click in any Query / Mutation class names in ApiHelper.kt
  3. That is even though classes generated , build log showing unable to find symbols

If I set GenerateKotlinModels to false , build is success.

If I set GenerateKotlinModels to true , build failed with above errors .

Thanks for all the details!

location: package com.localspace.work/Users/radicalstart/Documents/ragesh/android/sai-praveen-rentall-space-premium-android-v1.1/app/build/tmp/kapt3/...

That sounds like a kapt incremental build issue, I've had a few myself. Something like: https://youtrack.jetbrains.com/issue/KT-11978. Usually, they're resolved by removing the build directory and building again: rm -rf app/build

Thanks for all the details!

location: package com.localspace.work/Users/radicalstart/Documents/ragesh/android/sai-praveen-rentall-space-premium-android-v1.1/app/build/tmp/kapt3/...

That sounds like a kapt incremental build issue, I've had a few myself. Something like: https://youtrack.jetbrains.com/issue/KT-11978. Usually, they're resolved by removing the build directory and building again: rm -rf app/build


Yeah .. That error resolved is occurring again .

But that Builder not found error

 symbol:   class Builder
  location: class SearchListingQuery/Users/radicalstart/Documents/ragesh/android/sai-praveen-rentall-space-premium-android-v1.1/app/build/tmp/kapt3/stubs/debug/com/localspace/work/data/remote/ApiHelper.java:122: error: cannot find symbol
    com.localspace.work.GetAllReservationQuery.Builder query, int pageSize);

Why this builder not available in Kotlin models but available in Java ?

Why this builder not available in Kotlin models but available in Java ?

Kotlin uses data classes and default arguments so there's no real need for Builders there. You can call the constructor directly:

GetAllReservationQuery(/* variables go here */)

Why this builder not available in Kotlin models but available in Java ?

Kotlin uses data classes and default arguments so there's no real need for Builders there. You can call the constructor directly:

GetAllReservationQuery(/* variables go here */)

ooh I understand

But we used builder pattern in many places , So difficult to replace . So I stay with Java models

One question

What is the advantages of using Kotlin models ?

What is the advantages of using Kotlin models ?

I'd say it's the same reasons to use Kotlin in general: nullability support, data classes, default arguments, named arguments, etc... Also, if your codebase is 100% Kotlin, it saves the java compilation phase.

What is the advantages of using Kotlin models ?

I'd say it's the same reasons to use Kotlin in general: nullability support, data classes, default arguments, named arguments, etc... Also, if your codebase is 100% Kotlin, it saves the java compilation phase.

Ok understood

Thanks for your dedicated support

My issues resolved 馃檹

No problem! You're welcome.

@martinbonnin

Hi Martin . One additional query .

Is it possible to print the Query variables in logical as a JSON before sending them out ?

For example :

Query login ($name: String,$pass: String) .....

print vars as

{
name: "ragesh",
pass: "123"
}

(also tell for iOS also )

Is it possible to print the Query variables in logical as a JSON before sending them out ?

If it's for debug, I highly recomment the OkHttp logging interceptor: https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor

For other purposes, you can do something like below:

    val buffer = Buffer()
    val jsonWriter = JsonWriter.of(buffer)
    query.variables()
        .marshaller()
        .marshal(InputFieldJsonWriter(jsonWriter, CustomScalarAdapters.DEFAULT))
    val json = buffer.readUtf8()
Was this page helpful?
0 / 5 - 0 ratings

Related issues

itarato picture itarato  路  3Comments

tasomaniac picture tasomaniac  路  4Comments

rnitame picture rnitame  路  3Comments

gmrandom picture gmrandom  路  4Comments

juliafu1 picture juliafu1  路  4Comments