How to close the websocket in graphql config flutter?

How to close the websocket in graphql config flutter?


1

 class GraphqlConfig {
 final serverLink = Link.split(
      (request) => request.isSubscription,
      WebSocketLink(
        "mylink"
      ),
      HttpLink("mylink",
          defaultHeaders: <String, String>{
          
          }));

  initClient() {
    ValueNotifier<GraphQLClient> client = ValueNotifier(
      GraphQLClient(
        link: serverLink,
        cache: GraphQLCache(),
      ),
    );
    
return client;
  }

 GraphQLClient clientToQuery() {
    return GraphQLClient(
      cache: GraphQLCache(),
      link: serverLink,
    );
  }
}

I got the following exception

DOMException: Failed to execute 'close' on 'WebSocket': The code must be either 1000, or between 3000 and 4999. 1001 is neither.

1 Answer
1


0

You must call

client.dispose(); 

and

websocketLink.dispose();



Leave a Reply

Your email address will not be published. Required fields are marked *