Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] graphql – Android apollo subscriptions not working?

Posted on November 11, 2022 By

Solution 1 :

So there was no problem from my Code. The issue was with the free tier of Heroku I am using. I tried replacing my subscription with Hasura's Subscription https://hasura.io/learn/graphql/android/subscriptions/1-subscription/ and it works.

Problem :

I need to integrate subscription in my Android app. The subscription works fine on localhost in graphiql. I have deployed my backend on Heroku. I am using apollo-server and not hasura.
My subscriptions are not working for the url given by Heroku but it works fine on localhost. Queries and mutations work fine for both localhost and Heroku url.
So I am trying to access my subscription from my Android client. I have kept the base url as my local host. I have configured my Android emulator correctly for localhost and the queries and mutations part works for my Android client but my subscription part is not working.

I have configured my Apollo client for subscription by adding this

.subscriptionTransportFactory(WebSocketSubscriptionTransport.Factory(baseUrl,okHttpClient))

My subscription code looks as follows

val healthConsultationSubscriptionList = GetHealthConsultationSubscription.builder().build()
        apolloClient.subscribe(healthConsultationSubscriptionList).execute(object :
            ApolloSubscriptionCall.Callback<GetHealthConsultationSubscription.Data> {
            override fun onFailure(e: ApolloException) {
                Log.i("datafailure","${e.message} ${e.localizedMessage} ${e.cause}" )
            }

            override fun onResponse(response: Response<GetHealthConsultationSubscription.Data>) {
                Log.i("datais", response.data()?.healthConsultation()?.chiefComplaint().toString() )
            }

            override fun onConnected() {
                Log.i("dataconnected","Connected")
            }

            override fun onTerminated() {
                Log.i("dataterminated","Terminated")
            }

            override fun onCompleted() {
                Log.i("datacompleted","Completed")
            }

        })

But I keep getting an error saying Subscription failed Subscription failed java.net.ProtocolException: Expected HTTP 101 response but was '400 Bad Request'

Also when I use Graphiql for my subscription and replace localhost with the Heroku url for my subscription , I get following error.

enter image description here

Are these two issues which I am facing are related to one another?

READ  [FIXED] AWS Amplify GraphQL Unknown Directive in Android Studio
Powered by Inline Related Posts
Android Tags:apollo, apollo-android, apollo-server, graphql, graphql-subscriptions

Post navigation

Previous Post: [FIXED] android – Firebase recyclerview not showing anything when setHasFixedSize(true)
Next Post: [FIXED] java – How to Create a Thumbnail of mp3 file

Related Posts

[FIXED] For BottomNavigation the selected Item is not highlighted in android Android
[FIXED] android studio – AndroidStudio Kotlin connect to bluetooth Android
[FIXED] how to fix sms permission error android studio? Android
[FIXED] java – Android Studio Grid Layout Not Working Properly Android
[FIXED] java – Align ImageView inside WebView Android
[FIXED] How can I fix my android emulator not starting? Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme