Table of Contents

Action Cable Provider

The Action Cable Provider uses a channel to communicate with your front end using a web socket. First, you must ensure that you have properly set up Action Cable. Then you can use the provided GraphQL::BaseChannel or implement your own, taking advantage of the Rails::GraphQL::Channel concern.

The concern was designed to be easily overridden, allowing you to decide which parts you want to use and which ones you need to add or change the settings. For example, here is how you can add your own context:

# app/channels/graphql_channel.rb
class GraphQLChannel < ApplicationCable::Channel
  include GraphQL::Channel

  protected

    def gql_context(*)
      super.merge(current_user: current_user)
    end
end

Read more about customizing the Channel.

How it Works

The provider uses the Action Cable server and its underlying pub-sub mechanism to stream subsequent results from subscriptions. It will create one stream per subscription plus an internal asynchronous callback.

Here is everything that you can configure for this provider:

cable
::ActionCable - The Action Cable class
prefix
rails-graphql - The streams prefix
store
Rails::GraphQL::Subscription::Store::Memory.new - The store of the subscriptions
logger
Rails::GraphQL.logger - The logger