Last updated:
0 purchases
graphql action cable link
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:
copied to clipboard
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,
);
copied to clipboard
Similar to the HttpLink, ActionCableLink also supports defaultHeaders.
final actionCableLink = ActionCablelink(webSocketUrl, defaultHeaders: { 'x-time-zone': 'Australia/Sydney' });
copied to clipboard
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),
);
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.