zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.24k stars 612 forks source link

Subscription stuck with state: Initialising connection #1308

Closed vytautas-pranskunas- closed 1 year ago

vytautas-pranskunas- commented 1 year ago

I have this code:


    final websocketLink = WebSocketLink(
      subscriptionUri,
      config: SocketClientConfig(
        autoReconnect: true,
        delayBetweenReconnectionAttempts: const Duration(seconds: 2),
        initialPayload: () {
          return authTokenService.addAuthHeader(EnvVariables.currentHost);
        },
      ),
      subProtocol: GraphQLProtocol.graphqlTransportWs,
    );

    link = Link.split(
      (request) => request.isSubscription,
      websocketLink,
      link,
    );

but subscription stuck with state: Initialising connection and no messages are comming through. It would useful to have documentation (at least me - could not find it) or if you guys could share any possible reasons for this.

Without this i canno tmove my app to new backend which uses new protocol :(

p.s. I even reduced it to:

    final websocketLink = WebSocketLink(
      subscriptionUri,
      subProtocol: GraphQLProtocol.graphqlTransportWs,
    );

    link = Link.split(
      (request) => request.isSubscription,
      websocketLink,
      link,
    );
  }

by removing auth but result is the same....

vincenzopalazzo commented 1 year ago

mh could you please provide a reproduced with this API https://api.chat.graphql-flutter.dev/graphql

vytautas-pranskunas- commented 1 year ago

@vincenzopalazzo i have similar issue with url sandbox ou have provided. It is quite difficult to provide reproducable code because it is quite a lot happening inside an app but could we agree that you provide working example (it should have been in documentation which not exists yet) and if it works then i can 1) double check everything comapring to yours 2) dig deeper for possible reason 3) I will paste here either reproducable example or solution for other which you can include to documentation troubleshooting.

How about that?

p.s. my backend is used by WEB project and it works fine (as well as sandbox that you have provided)

vincenzopalazzo commented 1 year ago

@vytautas-pranskunas- you can check the PRs and also provide a review for it, for this reason the PR are opened

vytautas-pranskunas- commented 1 year ago

But this is already merged... don't you have tests? So you would not be providing working example right? How you can be sure of it works of you b do not have working example?

vincenzopalazzo commented 1 year ago

How you can be sure of it works of you b do not have working example?

I told you already, check the PR https://github.com/zino-hofmann/graphql-flutter/pull/1204 to the the example and maybe review it, so I can apply the suggestion and merge it

vytautas-pranskunas- commented 1 year ago

@vincenzopalazzo I have tested even further and what i have found that i was confused by that message: I/flutter ( 4558): Initialising connection because messages are received just message is wrong it should be Connected to websocket

vincenzopalazzo commented 1 year ago

For this reason, reproduction is needed when someone submits an issue!

Regarding the log message I will have a better solution to trace the library with https://github.com/zino-hofmann/graphql-flutter/pull/1207

vytautas-pranskunas- commented 1 year ago

So at the end what you want me to do? :) ignore message or?

vincenzopalazzo commented 1 year ago

So at the end what you want me to do? :) ignore message or?

PRs are welcome!

vytautas-pranskunas- commented 1 year ago

I see. However it would be much quicker for author (you) to fix this one because the time i need to get into this package for such small issue will be 10x times comparing to author. If there is a bigger issue then i do not mind.

vincenzopalazzo commented 1 year ago
➜  graphql-flutter git:(main) git grep "Initialising connection"
packages/graphql/lib/src/links/websocket_link/websocket_client.dart:      print('Initialising connection');

Just that, 10 seconds for everyone not just for me, if you make a PR please follow https://zino-hofmann.github.io/graphql-flutter/docs/dev/MAINTAINERS.html

vytautas-pranskunas- commented 1 year ago

Heh, this is 10s you are right, but what I was talking about it is not about the message it slef but about possibility that thi smessage is just intermediate state! like: Disconnected Initializing Connected

So in order to understand this i need to get into the code and this is time consuming thing ;)

vytautas-pranskunas- commented 1 year ago

however, few lines bellow there is a line with:

_connectionStateController.add(SocketConnectionState.connected);

mabe we need to add another message there print('Connected to websocket');

vytautas-pranskunas- commented 1 year ago

PR is added: https://github.com/zino-hofmann/graphql-flutter/pull/1309