[英]graphql-flutter subscriptions in flutter connectivity issue
I am new to flutter development but I have good experience in nodejs and graphql. I am trying to consume the subscription widget of graphql-flutter and update the changes.我是 flutter 开发的新手,但我在 nodejs 和 graphql 方面有很好的经验。我正在尝试使用 graphql-flutter 的订阅小部件并更新更改。 but the connection is not being established.但未建立连接。 But I could use the query and Mutation widget and get the results.但我可以使用查询和突变小部件并获得结果。 The examples provided by the graphql-flutter team is 2 years old and same with https://hasura.io/ documents. graphql-flutter 团队提供的示例已有 2 年历史,与https://hasura.io/文档相同。 Can someone help me providing the latest examples or samples.有人可以帮我提供最新的例子或样品吗?
graphql-flutter:^5.0.0 graphql-flutter:^5.0.0
If additional infos needed please comment below.如果需要其他信息,请在下面评论。
Thanks in advance提前致谢
I made a class that I use with graphql but it'll be able to work with graphql-flutter but passing the client to我制作了一个 class 与graphql 一起使用,但它可以与graphql-flutter一起使用,但将客户端传递给
return GraphQLProvider(
client: Services().graphQL.client, // just how I have my services set up
child: MaterialApp(
title: 'Flutter Demo',
...
),
);
class: class:
class GraphQL {
static final HttpLink _httpLink = HttpLink(environment[envMode]!['server']);
static WebSocketLink _wsLink(String token) => WebSocketLink(
environment[envMode]!['webSocket'],
config: SocketClientConfig(
inactivityTimeout: const Duration(hours: 1),
initialPayload: {
'Authorization': 'Bearer $token',
},
),
);
Link _splitLink(String token) => Link.split(
(request) => request.isSubscription,
_wsLink(token),
_httpLink,
);
GraphQLClient client(String token) {
return GraphQLClient(
link: AuthLink(getToken: () async => 'Bearer $token')
.concat(_splitLink(token)),
cache: GraphQLCache(
store: HiveStore(),
),
);
}
Future<void> initHive() async {
return await initHiveForFlutter();
}
}
The environment
and envMode
come from a config file that has gets its data from an env file to keep manage env and secrets. environment
和envMode
来自一个配置文件,该文件从 env 文件中获取数据以保持管理 env 和机密。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.