graphql_action_cable_link 0.1.0 copy "graphql_action_cable_link: ^0.1.0" to clipboard
graphql_action_cable_link: ^0.1.0 copied to clipboard

A Link for GraphQL Subscription backed by Rails ActionCable WebSocket server (graphql-ruby.org)

graphql_action_cable_link #

GraphQL Action Cable Link


A Graphql Subscription Link.

This only works for Rails server that uses graphql-ruby and ActionCable implementation for Subscription.

Installation #

First, depend on this package

dependencies:
  graphql_action_cable_link:

Usage #

Make sure your graphql's subscription is backed by ActionCable, see https://graphql-ruby.org/subscriptions/action_cable_implementation.html for more details how to implement GraphQL subscription with Action Cable.

Basic usage:

final graphqlEndpoint = 'http://localhost:3333/graphql';
final webSocketUrl = 'ws://localhost:3333/cable';
final actionCableLink = ActionCableLink(webSocketUrl);
final httpLink = HttpLink(graphqlEndpoint);

// create a split link
final link = Link.split(
  (request) => request.isSubscription,
  actionCableLink,
  httpLink,
);

final graphqlClient = GraphQLClient(
  cache: GraphQLCache(),
  link: link,
);

Similar to the HttpLink, ActionCableLink also supports defaultHeaders.

final actionCableLink = ActionCablelink(webSocketUrl, defaultHeaders: { 'x-time-zone': 'Australia/Sydney' });

ActionCableLink also supports authentication header by providing a function that returns the token:

String getAuthToken() {
  return 'Bearer auth-token';
}

final actionCableLink = ActionCableLink(
  webSocketUrl,
  getAuthTokenFunc: getAuthToken,
);

final httpLink = HttpLink(graphqlEndpoint);
final authLink = AuthLink(getToken: getAuthToken);
final link = Link.split(
  (request) => request.isSubscription,
  actionCableLink,
  authLink.concat(httpLink),
);
2
likes
120
pub points
16%
popularity

Publisher

verified publisherthue.do

A Link for GraphQL Subscription backed by Rails ActionCable WebSocket server (graphql-ruby.org)

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

action_cable, flutter, gql_exec, graphql_flutter

More

Packages that depend on graphql_action_cable_link