@@ -141,10 +141,37 @@ class SocketClientConfig {
141141 }
142142}
143143
144+ /// All the protocol supported by the library
145+ @Deprecated (
146+ "`SocketSubProtocol`is deprecated and will be removed in the version 5.2.0, consider to use `GraphQLProtocol`" )
144147class SocketSubProtocol {
145148 SocketSubProtocol ._();
146149
150+ /// graphql-ws: The new (not to be confused with the graphql-ws library).
151+ /// NB. This protocol is it no longer maintained, please consider
152+ /// to use `SocketSubProtocol.graphqlTransportWs` .
153+ static const String graphqlWs = GraphQLProtocol .graphqlWs;
154+
155+ /// graphql-transport-ws: New ws protocol used by most Apollo Server instances
156+ /// with subscriptions enabled use this library.
157+ /// N.B: not to be confused with the graphql-ws library that implement the
158+ /// old ws protocol.
159+ static const String graphqlTransportWs = GraphQLProtocol .graphqlWs;
160+ }
161+
162+ /// ALL protocol supported by the library
163+ class GraphQLProtocol {
164+ GraphQLProtocol ._();
165+
166+ /// graphql-ws: The new (not to be confused with the graphql-ws library).
167+ /// NB. This protocol is it no longer maintained, please consider
168+ /// to use `SocketSubProtocol.graphqlTransportWs` .
147169 static const String graphqlWs = "graphql-ws" ;
170+
171+ /// graphql-transport-ws: New ws protocol used by most Apollo Server instances
172+ /// with subscriptions enabled use this library.
173+ /// N.B: not to be confused with the graphql-ws library that implement the
174+ /// old ws protocol.
148175 static const String graphqlTransportWs = "graphql-transport-ws" ;
149176}
150177
@@ -159,7 +186,7 @@ class SocketSubProtocol {
159186class SocketClient {
160187 SocketClient (
161188 this .url, {
162- this .protocol = SocketSubProtocol .graphqlWs,
189+ this .protocol = GraphQLProtocol .graphqlWs,
163190 this .config = const SocketClientConfig (),
164191 @visibleForTesting this .randomBytesForUuid,
165192 @visibleForTesting this .onMessage,
@@ -247,14 +274,14 @@ class SocketClient {
247274 await config.connect (uri: Uri .parse (url), protocols: [protocol]);
248275 socketChannel = connection.forGraphQL ();
249276
250- if (protocol == SocketSubProtocol .graphqlTransportWs) {
277+ if (protocol == GraphQLProtocol .graphqlTransportWs) {
251278 _connectionStateController.add (SocketConnectionState .handshake);
252279 } else {
253280 _connectionStateController.add (SocketConnectionState .connected);
254281 }
255282 print ('Initialising connection' );
256283 _write (initOperation);
257- if (protocol == SocketSubProtocol .graphqlTransportWs) {
284+ if (protocol == GraphQLProtocol .graphqlTransportWs) {
258285 // wait for ack
259286 // this blocks to prevent ping from being called before ack is recieved
260287 await _messages.firstWhere (
@@ -263,10 +290,10 @@ class SocketClient {
263290 }
264291
265292 if (config.inactivityTimeout != null ) {
266- if (protocol == SocketSubProtocol .graphqlWs) {
293+ if (protocol == GraphQLProtocol .graphqlWs) {
267294 _disconnectOnKeepAliveTimeout (_messages);
268295 }
269- if (protocol == SocketSubProtocol .graphqlTransportWs) {
296+ if (protocol == GraphQLProtocol .graphqlTransportWs) {
270297 _enqueuePing ();
271298 }
272299 }
@@ -277,7 +304,7 @@ class SocketClient {
277304 onMessage !(message);
278305 }
279306
280- if (protocol == SocketSubProtocol .graphqlTransportWs) {
307+ if (protocol == GraphQLProtocol .graphqlTransportWs) {
281308 if (message.type == 'ping' ) {
282309 _write (PongMessage ());
283310 } else if (message.type == 'pong' ) {
@@ -494,7 +521,7 @@ class SocketClient {
494521 id,
495522 serialize (payload),
496523 );
497- if (protocol == SocketSubProtocol .graphqlTransportWs) {
524+ if (protocol == GraphQLProtocol .graphqlTransportWs) {
498525 operation = SubscribeOperation (
499526 id,
500527 serialize (payload),
@@ -512,7 +539,7 @@ class SocketClient {
512539 _subscriptionInitializers.remove (id);
513540
514541 sub? .cancel ();
515- if (protocol == SocketSubProtocol .graphqlWs &&
542+ if (protocol == GraphQLProtocol .graphqlWs &&
516543 _connectionStateController.value == SocketConnectionState .connected &&
517544 socketChannel != null ) {
518545 _write (StopOperation (id));
0 commit comments