Apollo Subscriptions

graphql-ruby-client includes support for subscriptions with ActionCable and Apollo client.

To use it, require subscriptions/addGraphQLSubscriptions and call the function with your network interface and ActionCable consumer.

With this configuration, subscription queries will be routed to ActionCable.

For example:

// Load ActionCable and create a consumer
var ActionCable = require('actioncable')
var cable = ActionCable.createConsumer()
window.cable = cable

// Load ApolloClient and create a network interface
var apollo = require('apollo-client')
var RailsNetworkInterface = apollo.createNetworkInterface({
 uri: '/graphql',
 opts: {
   credentials: 'include',
 headers: {
   'X-CSRF-Token': $("meta[name=csrf-token]").attr("content"),

// Add subscriptions to the network interface
var addGraphQLSubscriptions = require("graphql-ruby-client/subscriptions/addGraphQLSubscriptions")
addGraphQLSubscriptions(RailsNetworkInterface, {cable: cable})

// Optionally, add persisted query support:
var OperationStoreClient = require("./OperationStoreClient")

See the Subscriptions guide for information about server-side setup.