简体   繁体   English

Websocket 重连循环,graphql_flutter

[英]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.

相关问题 如何在 graphql_flutter 中重试对 GraphQLError 的请求 - How to retry a request on GraphQLError in graphql_flutter 使用 graphql_flutter 连接到 Graphql API 时出错 - Error when connecting to Graphql API using graphql_flutter Flutter with Firebase JWT 将 GraphQL (graphql_flutter) 请求发送到具有“格式错误的授权标头”的 Heroku Hasura - Flutter with Firebase JWT sends GraphQL (graphql_flutter) request to Heroku Hasura that has a “Malformed Authorization header” Flutter (graphql_flutter + gql):找到这个候选,但参数不匹配 - Flutter (graphql_flutter + gql): Found this candidate, but the arguments don't match graphql_flutter 返回 LazyCacheMap,built_value deserializeWith JSON String,如何让它们协同工作 - graphql_flutter return LazyCacheMap, built_value deserializeWith JSON String, how to make them work together 在操场上运行的 Graphql_flutter 突变在运行设备/模拟器上不起作用 - Graphql_flutter mutation running on playground doesn't work on running device/emulator 如何在每次构建Query()时禁用graphql_flutter查询后端 - How to disable graphql_flutter query backend every time build Query() graphql_flutter 突变查询需要返回语句 - 不确定如何添加它 - graphql_flutter mutation query expects return statement - not sure how to add it graphql_flutter - 从 pub.dev 页面复制代码 - 仍然出错 - graphql_flutter - copied code from the pub.dev page - still getting error Flutter websocket - Flutter websocket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM