[英]Websocket reconnection loop, graphql_flutter
I am using graphql_flutter
package in my app.我在我的应用程序中使用graphql_flutter
package。 This is the code for my client:这是我的客户的代码:
HttpLink httpLink = HttpLink(
uri: 'https://*******/graphql',
);
WebSocketLink webSocketLink = WebSocketLink(
url: "wss://*******/graphql/websocket/",
config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: Duration(seconds: 30),
),
);
AuthLink authLink = AuthLink(
getToken: ()async{
print(await SharedPreferencesHelper.getAuthenticationToken());
return "Bearer ${await SharedPreferencesHelper.getAuthenticationToken()}";
}
);
Link link = authLink.concat(httpLink);
link = link.concat(webSocketLink);
client = ValueNotifier(
GraphQLClient(
cache: InMemoryCache(),
link: link,
),
);
However whenever I create a subscription like this:但是,每当我创建这样的订阅时:
client.value.subscribe(Operation(
document: Subscriptions.chatMessageReceived,
variables: {
"receiverId": *******
}
)).listen((fetchResult){
print(fetchResult.data);
});
I get this log in repetition:我得到这个日志重复:
Connecting to websocket: wss://******/graphql/websocket/... flutter: Connected to websocket.连接到 websocket:wss://******/graphql/websocket/... flutter:连接到 websocket。 flutter: Disconnected from websocket. flutter:与 websocket 断开连接。 flutter: Scheduling to connect in 5 seconds... flutter: Connecting to websocket: wss://******/graphql/websocket/... flutter:计划在 5 秒内连接...
Even though everything works fine in graphql playground.即使在 graphql 操场上一切正常。 What can it be?会是什么?
this is because of inactivityTimeout: Duration(seconds: 30), in WebSocketLink config you can increase the Duration to prevent it from auto disconnecting.这是因为 inactivityTimeout: Duration(seconds: 30),在 WebSocketLink 配置中,您可以增加 Duration 以防止它自动断开连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.