Apollo-android: Failed to parse http response but before i get correct data

Created on 12 Sep 2018  路  7Comments  路  Source: apollographql/apollo-android

I now this is child task but i cannot resolve it.
I try this code:

MyApolloClient.getMyApolloClient().query(GetSQuery.builder().build())
                .enqueue(new ApolloCall.Callback<GetSQuery.Data>() {
                    @Override
                    public void onResponse(@Nonnull Response<GetSQuery.Data> response) {
                        try {
                            Log.d(TAG, "onResponce: " + response.data().getS().ts().toString());
                        } catch (Exception e) {
                            e.printStackTrace();
                        }


                    }

                    @Override
                    public void onFailure(@Nonnull ApolloException e) {
                        Log.d(TAG, "onFailed: " + e.getMessage());
                    }
                });

And try this Query:

`query getSQuery{
   getS{
     ts
     topic
     value
   }
 }`

And i get correct results but not correct parse result:

 ` 
 D/OkHttp: {"data":{"getSensor":{"__typename":"Sensor","ts":1536752717,"topic":"dev/pv/00-04-a3-0b-00-22-79-ef/status/1","value":5380576}}}
 D/MainActivity: onFailed: Failed to parse http response
 `

Thank you all!

Most helpful comment

I have a similar issue with this, usually is because the type of the field requested is not being passed by apollo. I remove all fields and adding one by one until get this problem ride off, once you have found the incorrect field you should fix in your backend. I had a date issue and my adapter was not converting in the correct way so I get many times that kind of error and I spent at least 3 days trying to fix it. I hope it can helps you.

All 7 comments

Sorry but the response seems not in sync with query. In query you ask for getS but in response theres getSensor

Sorry it's I'm correct in my posting code. In my work project i have getSensor in all place

Could you print the whole stack trace of the error

I am try oldest version 0.4.1 and it work fine! My stacktrace in actual version:

`09-17 17:53:34.596 23713-23713/? I/zygote64: Late-enabling -Xcheck:jni
09-17 17:53:34.939 23713-23713/com.example.qitment.learnapollo I/InstantRun: starting instant run server: is main process
09-17 17:53:35.254 23713-23713/com.example.qitment.learnapollo D/NetworkSecurityConfig: No Network Security Config specified, using platform default
09-17 17:53:35.318 23713-23741/com.example.qitment.learnapollo D/OpenGLRenderer: HWUI GL Pipeline
09-17 17:53:35.321 23713-23742/com.example.qitment.learnapollo D/OkHttp: --> POST http://x.x.x.x:8080/graphql
    Content-Type: application/json; charset=utf-8
    Content-Length: 137
    Accept: application/json
    X-APOLLO-OPERATION-ID: 56733836b2cb10a79a8f3bd85e57e2332cb48531e3f36152ebaf2fb172ec5abc
    X-APOLLO-OPERATION-NAME: getSensorQuery
09-17 17:53:35.322 23713-23742/com.example.qitment.learnapollo D/OkHttp: X-APOLLO-CACHE-KEY: c9cc68c3c59a1e582725e2e35a97446a
    X-APOLLO-CACHE-FETCH-STRATEGY: NETWORK_ONLY
    X-APOLLO-EXPIRE-TIMEOUT: 0
    X-APOLLO-EXPIRE-AFTER-READ: false
    X-APOLLO-PREFETCH: false
    {"query":"query getSensorQuery {  getSensor {    __typename    ts    topic    value  }}","operationName":"getSensorQuery","variables":{}}
    --> END POST (137-byte body)
09-17 17:53:35.363 23713-23741/com.example.qitment.learnapollo I/Adreno: QUALCOMM build                   : 624c5bb, I109c45a694
    Build Date                       : 05/22/18
    OpenGL ES Shader Compiler Version: EV031.22.00.01_06
    Local Branch                     : 
    Remote Branch                    : 
    Remote Branch                    : 
    Reconstruct Branch               : 
09-17 17:53:35.364 23713-23741/com.example.qitment.learnapollo D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8953.so from current namespace instead of sphal namespace.
09-17 17:53:35.369 23713-23741/com.example.qitment.learnapollo I/Adreno: PFP: 0x005ff087, ME: 0x005ff063
09-17 17:53:35.375 23713-23741/com.example.qitment.learnapollo I/zygote64: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
09-17 17:53:35.375 23713-23741/com.example.qitment.learnapollo I/OpenGLRenderer: Initialized EGL, version 1.4
09-17 17:53:35.375 23713-23741/com.example.qitment.learnapollo D/OpenGLRenderer: Swap behavior 2
09-17 17:53:35.431 23713-23741/com.example.qitment.learnapollo D/vndksupport: Loading /vendor/lib64/hw/[email protected] from current namespace instead of sphal namespace.
09-17 17:53:35.432 23713-23741/com.example.qitment.learnapollo D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8953.so from current namespace instead of sphal namespace.
09-17 17:53:35.518 23713-23742/com.example.qitment.learnapollo D/OkHttp: <-- 200 http://x.x.x.x:8080/graphql (195ms)
    Content-Type: application/json;charset=UTF-8
    Content-Length: 81
    Date: Mon, 17 Sep 2018 14:53:36 GMT
09-17 17:53:35.520 23713-23742/com.example.qitment.learnapollo D/OkHttp: {"data":{"getSensor":{"__typename":"Sensor","ts":123,"topic":"123","value":321}}}
    <-- END HTTP (81-byte body)
09-17 17:53:35.539 23713-23742/com.example.qitment.learnapollo D/MainActivity: onFailed: Failed to parse http response
`

Query / response seem legit. Could you pls print the stack trace of the error you getting in the onFailed callback? And please join our slack http://www.apollostack.com/#slack and ping me there, might be faster

I have a similar issue with this, usually is because the type of the field requested is not being passed by apollo. I remove all fields and adding one by one until get this problem ride off, once you have found the incorrect field you should fix in your backend. I had a date issue and my adapter was not converting in the correct way so I get many times that kind of error and I spent at least 3 days trying to fix it. I hope it can helps you.

@piercruz Great thanks for answer but i already find decisions. Yes my problem was in some field (custom scalar type):
`Caused by: java.lang.IllegalArgumentException: Can't map GraphQL type: Long to: class java.lang.Object. Did you forget to add custom type adapter
`
Great thanks for help @sav007 , i add this line and all become okay.

apollo {
  customTypeMapping = [
    "Long" : "java.lang.Long"
  ]
}

More about custom scalar type you can learn from this article:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pratthama-appdesk picture pratthama-appdesk  路  3Comments

mmahesh2019 picture mmahesh2019  路  4Comments

gmrandom picture gmrandom  路  4Comments

romainpiel picture romainpiel  路  4Comments

rnitame picture rnitame  路  3Comments