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
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
Version:
Apollo version : : 2.4.6
Gradle build tools: : 4.1.1
Gradle : 6.7.1
Kotlin : : 1.3.72
dagger : 2.24
points :
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
builddirectory 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()
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.