我在我的应用中使用graphql_flutter
软件包。这是我的客户的代码:
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,
),
);
但是无论何时我创建这样的订阅:
client.value.subscribe(Operation(
document: Subscriptions.chatMessageReceived,
variables: {
"receiverId": *******
}
)).listen((fetchResult){
print(fetchResult.data);
});
我得到此日志重复:
连接到Websocket:wss:// ****** / graphql / websocket / ... 已连接到websocket。颤动:与websocket断开连接。扑: 计划在5秒钟内连接...颤抖:正在连接 websocket:wss:// ****** / graphql / websocket / ...
即使在graphql操场上一切正常。会是什么?
答案 0 :(得分:0)
这是因为不活动超时:持续时间(秒:30),在WebSocketLink配置中 您可以增加持续时间以防止其自动断开连接。