Apollo-android: [Solved] Failed to execute http call

Created on 15 Oct 2018  路  3Comments  路  Source: apollographql/apollo-android


[EDIT2] fixed by adding the following in the android manifest

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <application
        ...
        android:usesCleartextTraffic="true">

Between the error message "Failed to execute http call" is pretty bad.. I had to install and setup a basic conf with Volley to find what's happening..

Hi, I try to get working a very basic app.
My schema are downloaded using apollo cli, my graphQL API is working perfectly (tested the query on playground) and run locally on http://localhost:4000/ (this is the endpoint).

[EDIT] If I set BASE_URL to http://10.0.2.2:4000 I got the same error for the app. But I can access to the graphql playground through google chrome from the emulator.

schema.json and the .graphql file are located under the /graphql directory.
The project is building without any error, apollo-android generate all stuff finely.

Exception:

com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$1$1.onFailure(ApolloServerInterceptor.java:89)
okhttp3.RealCall$AsyncCall.execute(RealCall.java:148)
okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
java.lang.Thread.run(Thread.java:764)
Failed to execute http call

I missed something ?

Most helpful comment

None of those things worked for me.
Why is apollo making a network failure a fatal error?

All 3 comments

None of those things worked for me.
Why is apollo making a network failure a fatal error?

Where is the solution?

Calls to the insecure http protocol will not work with Android as part of their security policy. You need https.
Set up a secure tunnel to localhost (I know, counter-intuitive, but hey) by executing the following in a terminal

  1. npm install ngrok -g
  2. ngrok http 4000 <- this is the port for the graphql endpoint on localhost
  3. copy the secure https protocol that the command line gives you for example https://93c28b4e13cc.ngrok.io
  4. paste that in your apollo implementation
    val apolloClient = ApolloClient.builder()
    .serverUrl("https://93c28b4e13cc.ngrok.io")
    .build()
  5. enjoy building your queries!
Was this page helpful?
0 / 5 - 0 ratings