gql_websocket_link

Last updated:

0 purchases

gql_websocket_link Image
gql_websocket_link Images
Add to Cart

Description:

gql websocket link

GQL WebSocket link to execute subscriptions as well as mutations & queries against a GraphQL backend.
This link support autoReconnect and will resubscribe after reconnecting.
This package supports both the deprecated graphql-ws and the graphql-transport-ws protocol
via the WebSocketLink and TransportWebSocketLink classes respectively.
Usage #
WebSocketLink / graphql-ws protocol #
import "package:gql_link/gql_link.dart";
import "package:gql_websocket_link/gql_websocket_link.dart";

void main () {
final link = Link.from([
// SomeLink(),
WebSocketLink("ws://<GRAPHQL_SERVER_ENDPOINT>/graphql"),
]);
}

copied to clipboard
TransportWebSocketLink / graphql-transport-ws protocol #
import "package:gql_link/gql_link.dart";
import "package:gql_websocket_link/gql_websocket_link.dart";

void main () {
final link = Link.from([
// SomeLink(),
TransportWebSocketLink(
TransportWsClientOptions(
socketMaker: WebSocketMaker.url(() => "ws://<GRAPHQL_SERVER_ENDPOINT>/graphql")
),
),
]);
}

copied to clipboard
Websocket Sub-Protocols And Their Dart Implementations #
There are two websocket sub-protocols available for GraphQL supported by this package:

graphql-ws (also known as subscriptions-transport-ws, which is the name of the npm package which implements it, spec])
graphql-transport-ws (confusingly, also known as graphql-ws, which is the name of the npm package which implements it spec)

In this document, we will refer to the protocols not by their npm package names, but by the name of the sub-protocol.
See also the Apollo docs.
Generally, you should use graphql-transport-ws if your server supports it.
In order to use graphql-transport-ws, you need to use the TransportWebSocketLink class.
For graphql-ws, use the WebSocketLink class.
The WebSocketLink class has some known issues, see:

https://github.com/gql-dart/gql/issues/430

Features and bugs #
Please file feature requests and bugs at the GitHub.
Attribution #
This code was adapted with minor changed from the graphql-flutter repo

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.