gql_websocket_link 2.0.1 copy "gql_websocket_link: ^2.0.1" to clipboard
gql_websocket_link: ^2.0.1 copied to clipboard

GQL Websocket Link

MIT License PRs Welcome Watch on GitHub Star on GitHub Watch on GitHub Discord

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 #

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
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:

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

13
likes
120
points
6.5k
downloads

Publisher

verified publishergql-dart.dev

Weekly Downloads

2024.10.03 - 2025.04.17

GQL Websocket Link

Repository (GitHub)

Topics

#graphql #gql #gql-link

Documentation

API reference

License

MIT (license)

Dependencies

gql, gql_exec, gql_link, meta, rxdart, uuid, web_socket_channel

More

Packages that depend on gql_websocket_link