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.