Open-source project
anycable/graphql-anycable avatar
anycable/graphql-anycable

graphql-anycable: Moving GraphQL subscriptions off ActionCable without losing the API

A drop-in replacement for GraphQL ActionCable subscriptions. Works with AnyCable.

114 stars20 forksRubyMIT

At a glance

What is it?
graphql-anycable is a drop-in adapter that lets the graphql gem run subscriptions over AnyCable, storing state in Redis and re-executing queries at event time. It works, but you must plan Redis cleanup and know where the broadcast option changes behavior.
Who is it for?
Adopt graphql-anycable if you run a Rails or non-Rails GraphQL API with AnyCable and want subscriptions without forcing Ruby execution into the cable process. Do not adopt it if you cannot tolerate Redis as a hard dependency or if you expect per-client query execution to be cheap at scale.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 94 days ago.
What is it written in?
Mainly Ruby, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • anycable/graphql-anycable114 ★ · +0
Star history
Repository2026-08-212026-11-23
anycable/graphql-anycable114114

0 Stars in the last 94 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The problem this gem actually solves

AnyCable is fast because it moves the WebSocket connection out of Ruby. The graphql gem's default ActionCable subscriptions adapter, however, expects to re-evaluate GraphQL queries inside the ActionCable process. That is exactly what AnyCable avoids. The graphql-anycable gem steps in as a replacement adapter that stores subscription state in Redis and re-executes the queries in whatever process triggers an event. That process can be a web server, a background job, a rake task, or anything else. The audience is a Rails or even non-Rails Ruby application that already runs AnyCable and wants GraphQL subscriptions without forcing Ruby back into the connection layer.

How subscription state moves to Redis

The README is explicit about the core difference: subscription information is stored in Redis, and by default it uses the same Redis configuration as AnyCable. When a client subscribes through a GraphQL channel, the gem records the subscription in Redis. When an event fires, the gem re-executes the GraphQL query in the process that triggered the event, then transmits the result to the relevant clients. This means the cable server itself never executes GraphQL. The trade-off is that every event does query work somewhere, and that Redis becomes a required piece of infrastructure. There is no in-memory subscription store. The gem also adds a channel key to the context, and the README warns that you must pass the channel instance as the channel key, otherwise subscription cleanup will not know which channel to remove.

Getting it running: the three steps from the README

Installation is a standard Gemfile line: gem "graphql-anycable", "~> 1.0", then bundle install. In your schema, replace the ActionCable adapter with use GraphQL::AnyCable, broadcast: true. The README shows the schema class calling use before defining subscription SubscriptionType. In your ActionCable or LiteCable channel, you execute queries as usual, but you must handle subscription results specially. The example channel transmits { data: nil } when result.subscription? is true, and sets more: result.subscription?. It also calls MySchema.subscriptions.delete_channel_subscriptions(self) in unsubscribed. Events are triggered with MySchema.subscriptions.trigger(:product_updated, {}, Product.first!, scope: account.id). The README notes that if you use a non-Redis broadcasting adapter, you must configure GraphQL::AnyCable.redis yourself, either with a Redis instance or a Proc that yields a connection from a pool.

Broadcasting: one execution for many clients, with a security caveat

By default, the gem evaluates and transmits results for each subscription client individually. The README calls this a waste of resources when hundreds of clients subscribe to the same data. The broadcast: true option enables GraphQL-Ruby's subscription broadcast feature, which groups identical subscriptions, executes them once, and transmits the result once. But there is a catch: by default, all fields are marked as not safe for broadcasting. If any field in a subscription query is non-broadcastable, GraphQL-Ruby falls back to executing every subscription independently. You can force all fields to be broadcastable with default_broadcastable: true, but the README warns this can have security implications. The implication is that you must audit your fields and mark them individually unless you accept the risk. The broadcast option does not change where queries run; it only changes how many times they run.

Redis cleanup is your responsibility, and it has knobs

The gem does not automatically expire subscription data. You must set subscription_expiration_seconds to a number of seconds, and you must run rake graphql:anycable:clean periodically. The README gives an example of 604800 for one week. The cleanup task has granular sub-tasks: clean:channels, clean:subscriptions, clean:fingerprint_subscriptions, and clean:topic_fingerprints. You can run them on different schedules. The cleanup uses Redis SCAN and pipelines checks per batch. The redis_scan_count setting tunes batch size. Larger values mean fewer round trips but more work per Redis call. There is also a use_redis_object_on_cleanup setting that Heroku users should set to false because of Heroku Redis connection permissions. If you skip expiration and cleanup, Redis fills with stale subscription data, and the README includes an emergency actions section for clearing subscriptions manually.

Configuration paths and the anyway_config dependency

Configuration comes through the anyway_config gem. You can set environment variables like GRAPHQL_ANYCABLE_SUBSCRIPTION_EXPIRATION_SECONDS, GRAPHQL_ANYCABLE_USE_REDIS_OBJECT_ON_CLEANUP, GRAPHQL_ANYCABLE_REDIS_PREFIX, and GRAPHQL_ANYCABLE_REDIS_SCAN_COUNT. You can also use a YAML file, but it must be config/graphql_anycable.yml, not config/anycable.yml. The README shows a production block with subscription_expiration_seconds: 300, use_redis_object_on_cleanup: false, redis_prefix: graphql, and redis_scan_count: 1000. Or you can configure in code with GraphQL::AnyCable.configure do |config| and set the same keys. The gem adds a hyphen after the redis_prefix on its own side, so a prefix of graphql becomes graphql- for actual Redis keys. This is a small detail but matters if you inspect Redis directly.

Limitations and the wrong tool cases

The most obvious limitation is that every event re-executes the GraphQL query. If you have high event rates and heavy queries, that load lands on your web or job processes, not on AnyCable. The broadcast option helps only when subscriptions are identical and fields are marked broadcastable, which requires discipline. Another limitation is the Redis dependency. If you use a non-Redis AnyCable broadcaster, you must configure a separate Redis connection for this gem, which adds another moving part. The README also warns that without subscription_expiration_seconds, stale data accumulates, and the cleanup task may not be enough in some scenarios. For very small apps, the overhead of Redis and cleanup tasks might be more than the default ActionCable adapter, which keeps everything in memory. This gem is the wrong tool if you cannot accept Redis as a required component or if you cannot schedule cleanup jobs.

Alternatives: the default adapter and LiteCable

The direct alternative is the default ActionCable subscriptions adapter that ships with the graphql gem. That adapter keeps subscription state in memory and re-evaluates queries in the ActionCable process. It works fine for small deployments, but it does not work with AnyCable, because AnyCable does not execute Ruby code. That is the entire reason this gem exists. Another alternative is to use LiteCable, which the README mentions as a non-Rails option. LiteCable is a lightweight ActionCable-compatible server, and graphql-anycable claims compatibility with it. The difference is that LiteCable still runs Ruby, so you could potentially use the default adapter there, though the gem's design targets AnyCable specifically. If you want to avoid Redis entirely, you would need to write your own subscription store or use a different GraphQL subscription implementation that does not rely on Redis.

Maintenance and licence notes

The gem is MIT licensed, which means you can use it in commercial projects without paying a fee, but you should read the license text yourself for exact terms. The repository shows active maintenance: the latest release v1.3.4 fixed expired subscription handling, v1.3.3 fixed leaking channel subscriptions and optimized their cleaning, and v1.3.2 optimized the stale subscription cleanup rake task. These release notes indicate that cleanup and subscription lifecycle are areas of ongoing bug fixes. The gem depends on anyway_config, so you inherit that dependency's configuration behavior. Upgrading the gem may change how cleanup works, as seen in the recent releases. You should test the cleanup rake task in a staging environment before upgrading in production, because the fixes changed how subscriptions are deleted.

Editorial conclusion

Adopt graphql-anycable if you run a Rails or non-Rails GraphQL API with AnyCable and want subscriptions without forcing Ruby execution into the cable process. Do not adopt it if you cannot tolerate Redis as a hard dependency or if you expect per-client query execution to be cheap at scale. Before you commit, verify your Redis setup supports SCAN and pipelining for cleanup, set subscription_expiration_seconds, and run rake graphql:anycable:clean on a schedule. If you need true fan-out without re-execution, look at broadcast: true and read the GraphQL-Ruby broadcast docs first.

Frequently asked questions

What does the graphql-anycable gem do?

It replaces the subscriptions adapter that ships with the graphql gem so GraphQL subscriptions work with AnyCable, which does not execute Ruby code. Subscription state is kept in Redis and the query is evaluated once in the process that triggers the event rather than once per subscriber.

How do I install graphql-anycable?

Add gem "graphql-anycable", "~> 1.0" to your Gemfile and run bundle install. Then plug it into the schema with use GraphQL::AnyCable, broadcast: true, and make sure you pass the channel instance as the channel key in the context.

What are GraphQL subscriptions used for?

In this gem they carry live updates to a connected client. A trigger call names a topic, a payload, a subject and a scope, and every subscription matching that scope receives the re-executed query result, either as a broadcast shared across identical subscriptions or individually per client.

How do I clean up stale subscriptions in graphql-anycable?

Set subscription_expiration_seconds and run rake graphql:anycable:clean periodically. The task is also split into clean:channels, clean:subscriptions, clean:fingerprint_subscriptions and clean:topic_fingerprints so you can schedule them separately, and redis_scan_count tunes the SCAN batch size.

Where does the graphql-anycable YAML config file go?

In config/graphql_anycable.yml, and explicitly not in config/anycable.yml, which is AnyCable's own configuration file. Environment variables prefixed with GRAPHQL_ANYCABLE_ and a GraphQL::AnyCable.configure block are the two other supported routes, all provided by anyway_config.

Is default_broadcastable safe to enable in graphql-anycable?

The documentation warns it can have security implications. By default every field is marked not safe for broadcasting, and a subscription with even one non-broadcastable field falls back to per-client execution. Setting it true marks all fields shareable, which means a field that varies per user could send one client's data to others.

Official sources

  1. Official README
  2. Project repository
  3. Release notes
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/anycable-graphql-anycable.svg)](https://hysenlabs.com/projects/anycable-graphql-anycable)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/anycable-graphql-anycable.svg)](https://hysenlabs.com/projects/anycable-graphql-anycable)

Was this useful?