graphql-flutter
graphql-flutter copied to clipboard
How to wait for connection acknowledgement and then start subscription.
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: GraphQLProvider(
client: client,
child: Subscription(operationName, subscription, builder: ({
bool loading,
dynamic payload,
dynamic error,
}) {
if (loading==true) {
return LoadingAnimation();
}
print("Subscription payload: $payload");
return Query(
options: QueryOptions(
document: playDuel,
variables: {},
pollInterval: 10000,
),
builder: (QueryResult result, {VoidCallback refetch}) {
if (result.errors != null) {
print(result.errors);
}
if (result.loading) {
return LoadingAnimation();
}
print(result.data['playDuel']);
return Container();
});
}),
),
);
}
this loading function do not gives me live update about the connection. it always returns true. So all i want is to get data printed by Subscription widget on console get stored in some variable.
I have the same problem. No info on websocket connection state with this client :
final sessionToken = await storage.read(key: 'session_token');
AuthLink _authLink = AuthLink(
getToken: () async => 'Bearer $sessionToken',
);
HttpLink _httpLink = HttpLink(
uri: '$backendUrl/graphql',
);
print('je suis appelé');
final WebSocketLink websocketLink = WebSocketLink(
url: 'ws://12da74dc.ngrok.io/graphql',
config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: Duration(seconds: 30),
),
);
Link _link = _authLink.concat(_httpLink).concat(websocketLink);
client = ValueNotifier(GraphQLClient(
cache: InMemoryCache(),
link: _link,
));
And if I put anything for the websocket url it won't print an error. It doesn't say anything.
It works great with Queries and Mutations though