Vytautas Pranskunas
Vytautas Pranskunas

Reputation: 890

How to configure graphql-flutter and apollo sever that to make app stop disconnecting from websocket

I am building app on flutter where i am using graphql-flutter package and my config look like this:

final WebSocketLink websocketLink = WebSocketLink(
    url: subscriptionUri,
    config: SocketClientConfig(
        autoReconnect: true,
        initPayload: () {
          return authTokenService.addAuthHeader(EnvVariables.currentHost);
        }));

link = link.concat(websocketLink);

Also on backend i am using Apollo graphql with subscriptions and redis for PubSub which condfig looks like this:

this.pubsub = new RedisPubSub({
            publisher: new Redis(process.env.REDIS_URL),
            subscriber: new Redis(process.env.REDIS_URL),
        });

and Apollo

const apolloServer = new ApolloServer({
    schema,
    subscriptions: {
        keepAlive: 30000,  
    }...

All this is hosted on Heroku (not prod environment - free one - maybe thats an issue) So my app keeps disconnecting and reconnecting to websocket. enter image description here

just before disconnecting i am getting a message: Have'nt received keep alive message for 30 seconds. Disconnecting...

But if i pass null to inactivityTimeout in graphql-flutter package

final WebSocketLink websocketLink = WebSocketLink(
    url: subscriptionUri,
    config: SocketClientConfig(
        autoReconnect: true,
        inactivityTimeout: null,
        initPayload: () {
          return authTokenService.addAuthHeader(EnvVariables.currentHost);
        }));

link = link.concat(websocketLink);

After some time app throws error that - max retries limit reached.

So how should i configure both sides correctly? Should i send keepAlive messages or just ignore them on flutter side but then how to avoid max retries error? Or maybe i should manually send any message to channel to keep it active liek it says here: https://devcenter.heroku.com/articles/play-java-websockets-advanced (but i would expect that apollo server would do it for me...)

Thanks

Upvotes: 4

Views: 1888

Answers (1)

Vytautas Pranskunas
Vytautas Pranskunas

Reputation: 890

Since this library does not have acive maintainer I used custom fork where websocket client is replaced. https://github.com/zino-app/graphql-flutter/issues/892

Upvotes: 1

Related Questions