用阿波罗服务器订阅时GraphQL订阅异常
GraphQL订阅抛出异常“ Web套接字连接失败” 使用Apollo服务器订阅时。订阅与GraphQl Explorer合作正常,但是在扑面
代码中实现时失败,下面附加了异常。
**********代码
final _wsLink = WebSocketLink(
‘***************’,
config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: Duration(hours: 1),
// delayBetweenReconnectionAttempts: Duration(seconds: 1),
),
);
final Link _link = Link.split((request) => request.isSubscription, _wsLink, httpLink);
client = GraphQLClient(
cache: GraphQLCache(store: InMemoryStore()),
link: _link,
);
SubscriptionOptions options = SubscriptionOptions(
document: gql(query),
variables: variables);
final result = client.subscribe(options);
result.listen((event) {
print("Event fired ${event.data}");
print("Event fired ${event.exception?.graphqlErrors.toString()}");
}).onError((e) {
print("Received Error ! ${e.toString()}");
});
return result;
***************************************************************************************************************
i/flutter(5204):与Websocket断开连接。
GraphQl subscription throwing exception "web socket connect failed" when subscribing with Apollo server. Subscription is working fine with graphQl explorer but failing when implemented in flutter
Code and exceptions are attached below.
********** Code ***********
final _wsLink = WebSocketLink(
‘***************’,
config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: Duration(hours: 1),
// delayBetweenReconnectionAttempts: Duration(seconds: 1),
),
);
final Link _link = Link.split((request) => request.isSubscription, _wsLink, httpLink);
client = GraphQLClient(
cache: GraphQLCache(store: InMemoryStore()),
link: _link,
);
SubscriptionOptions options = SubscriptionOptions(
document: gql(query),
variables: variables);
final result = client.subscribe(options);
result.listen((event) {
print("Event fired ${event.data}");
print("Event fired ${event.exception?.graphqlErrors.toString()}");
}).onError((e) {
print("Received Error ! ${e.toString()}");
});
return result;
************ Exception ***************
I/flutter ( 5204): Disconnected from websocket.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我迟到了,但这对我有用,如果您有阿波罗服务器4
I'm late but this works for me, if you have Apollo Server 4