graphql-flutter
graphql-flutter copied to clipboard
How to know that web socket is connected in subscription widget.
I am using a subscription widget and how can I make sure that connection is established with the server and I can call it in the subscription widget.
here is my socket client connection
link = HttpLink(
uri:
'http://staginggraphql*********************,
headers: <String, String>{
'x-token': centralstate.GraphQLToken,
},
);
socketLink = WebSocketLink(
url: 'ws://staginggraphql*********************,
config: SocketClientConfig(
initPayload: {"authToken": "${centralstate.GraphQLToken}"},
autoReconnect: true,
inactivityTimeout: Duration(seconds: 30),
),
);
link = link.concat(socketLink);
client = ValueNotifier(
GraphQLClient(cache: InMemoryCache(), link: link),
);
Subscription widget:
GraphQLProvider(
client: client,
child: Subscription(
operationName,
"""subscription $operationName{
leagueGameStatusUpdate(leagueAppID:"${centralstate.leagueAppID}"){
appID
error
status
}
}""",
builder: ({
bool loading,
dynamic payload,
dynamic error,
}) {
//how to make sure that WebSocket is connected and then call playful function
game.playDuel().then((value) {
if (value != 'complete') {
print('error screen');
}
});
return PlayingAnimation();
},
)),
loading and payload always returns true and null I need to give some delay before calling game.playDuel() otherwise it will not work. I know I can ask it on stack overflow but I am not getting any response over there. Sorry but I need to fix this asap. thanks, any help would be appreciated.
+1. I would also like to know this event.
I have a PR for this here: https://github.com/zino-app/graphql-flutter/pull/580
Hey @eliezedeck , did you figure out how to know this event??
Hey @eliezedeck , did you figure out how to know this event??
Yes, see the PR above.
if I incorporate the changes. It's giving me error that subscribe was called on null.
I suspect there is something wrong with how you're using the library. That should probably be something easy to fix though. I'm sorry but I don't have the time resource to look into this for the time being.
EDIT: I'm using this myself, and I'm not having the same problem as you do. So, that's a fact to consider.
Try 4.0.0-alpha.6
, which has a revitalized version of WebSocketLink
and an overhauled subscription api. It also adds a Might make what you're trying to do easier.
It doesn't really expose the connection state. Maybe we should add loading responses to the stream while reconnection attempts are being made.