2
votes

I am developing an Android application using Kotlin. I am trying to consume GraphQL API using Apollo Client within my application. I installed the Apollo Client and generated the schema and classes successfully. Now I am making a mutation request and it is not returning any response.

This is my code

view.btn_login.setOnClickListener {
            val okHttp = OkHttpClient
                .Builder()
                .addInterceptor({ chain ->
                    val original = chain.request()
                    val builder = original.newBuilder().method(original.method(),
                        original.body())
                    chain.proceed(builder.build())
                })
                .build()
            val apolloClient = ApolloClient.builder()
                .serverUrl("https://my-app-name.herokuapp.com/graphql")
                .okHttpClient(okHttp)
                .build()

            val loginMutation = LoginMutation.builder()
                .identity(view.etf_email.text.toString())
                .password(view.etf_password.text.toString())
                .build()

            view.tv_login_error_message.text = "Started making request"
            apolloClient.mutate(loginMutation).enqueue(object: ApolloCall.Callback<LoginMutation.Data>() {
                override fun onFailure(e: ApolloException) {
                    view.tv_login_error_message.text = e.message
                }

                override fun onResponse(response: Response<LoginMutation.Data>) {
                    view.tv_login_error_message.text = "Request completed."
                }
            })
        }

When I click on the button, the message just says "Started making request" . It tooks a while, them the response error says, failed to execute HTTP call. What is wrong with my code and how can I fix it?

The followings are the permission I added in the manifest xml.

<uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.CAMERA"/>

This is what I get in the stacktrace

2019-09-15 22:54:13.027 20508-20580/com.example.memento E/MYAPP: exception
2019-09-15 22:54:13.027 20508-20580/com.example.memento W/System.err: com.apollographql.apollo.exception.ApolloNetworkException: Failed to execute http call
2019-09-15 22:54:13.028 20508-20580/com.example.memento W/System.err:     at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$2.onFailure(ApolloServerInterceptor.java:120)
2019-09-15 22:54:13.028 20508-20580/com.example.memento W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:211)
2019-09-15 22:54:13.028 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
2019-09-15 22:54:13.028 20508-20580/com.example.memento W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at java.lang.Thread.run(Thread.java:919)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err: Caused by: java.net.UnknownHostException: Unable to resolve host "memento-nova-api-staging.herokuapp.com": No address associated with hostname
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at java.net.InetAddress.getAllByName(InetAddress.java:1152)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at okhttp3.Dns$1.lookup(Dns.java:40)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:185)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:149)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:84)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:214)
2019-09-15 22:54:13.030 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
2019-09-15 22:54:13.031 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
2019-09-15 22:54:13.031 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
2019-09-15 22:54:13.031 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
2019-09-15 22:54:13.031 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
2019-09-15 22:54:13.031 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
2019-09-15 22:54:13.032 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
2019-09-15 22:54:13.032 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
2019-09-15 22:54:13.032 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
2019-09-15 22:54:13.032 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
2019-09-15 22:54:13.032 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
2019-09-15 22:54:13.033 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
2019-09-15 22:54:13.033 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
2019-09-15 22:54:13.033 20508-20580/com.example.memento W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:250)
2019-09-15 22:54:13.033 20508-20580/com.example.memento W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:201)
2019-09-15 22:54:13.033 20508-20580/com.example.memento W/System.err:   ... 4 more
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:     at libcore.io.Linux.android_getaddrinfo(Native Method)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:     at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:     at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:200)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:     at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:     at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:   ... 26 more
1
Can you include some more information about the error message? Is it produced by the onFailure callback method? If yes, then the ApolloException in the method may contain helpful information about what went wrong. You should also verify (if possible) that your request is received by the server.gmetal
That is the error message from ApolloException.Wai Yan Hein
I would try to print the complete stack trace of the exception to get more details about the actual error. An inner exception usually contains the real cause of the exception.gmetal
Hi @gmetal, I just updated the question adding the stacktrace details.Wai Yan Hein
@WaiYanHein did you check logs in Heroku? is your app running?Om Infowave Developers

1 Answers

3
votes

After looking at the stacktrace you posted, I believe that the actual cause of the error is the following line:

Caused by: java.net.UnknownHostException: Unable to resolve host

It appears that your device is unable to resolve the server URL through DNS. This means that your DNS server may be unreachable, or you've mistyped the server URL, or your device cannot access the DNS server for some reason (e.g. firewall). I would open a browser inside the device and try to connect to the server (just so that I can establish that a connection is possible).