我在flutter上构建应用程序,其中我使用graphql-flutter包,我的配置如下所示:
final WebSocketLink websocketLink = WebSocketLink(
url: subscriptionUri,
config: SocketClientConfig(
autoReconnect: true,
initPayload: () {
return authTokenService.addAuthHeader(EnvVariables.currentHost);
}));
link = link.concat(websocketLink);同样在后端,我使用带有订阅的Apollo graphql和PubSub的redis,它的condfig看起来像这样:
this.pubsub = new RedisPubSub({
publisher: new Redis(process.env.REDIS_URL),
subscriber: new Redis(process.env.REDIS_URL),
});和阿波罗
const apolloServer = new ApolloServer({
schema,
subscriptions: {
keepAlive: 30000,
}...所有这些都托管在Heroku上(不是prod环境--也许这是一个问题),所以我的应用程序总是断开连接,然后重新连接到websocket。

就在断开连接之前,我收到一条消息: 30秒内没有收到keep alive消息。正在断开连接...
但是如果我将null传递给graphql-flutter包中的inactivityTimeout
final WebSocketLink websocketLink = WebSocketLink(
url: subscriptionUri,
config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: null,
initPayload: () {
return authTokenService.addAuthHeader(EnvVariables.currentHost);
}));
link = link.concat(websocketLink);在一段时间后,应用程序会抛出达到- max重试次数限制的错误。
那么我应该如何正确配置两端呢?我应该发送keepAlive消息还是在颤动端忽略它们,但是如何避免最大重试错误?或者我应该手动发送任何消息到通道以使其保持活动状态,就像这里所说的:https://devcenter.heroku.com/articles/play-java-websockets-advanced (但我希望apollo服务器会为我做这件事……)
谢谢
发布于 2021-06-30 03:34:02
由于这个库没有可用的维护者,所以我使用了自定义fork,其中替换了websocket客户端。https://github.com/zino-app/graphql-flutter/issues/892
https://stackoverflow.com/questions/64145876
复制相似问题