graphql-anycable
A drop-in replacement for GraphQL ActionCable subscriptions. Works with AnyCable.
GraphQL AnyCable replaces ActionCable subscriptions with a Redis backed adapter
The Ruby gem is a mostly drop in replacement for the GraphQL gem's default subscription adapter that works with AnyCable for better performance.
Why it exists
GraphQL AnyCable is a mostly drop in replacement for the default ActionCable subscriptions adapter shipped with the GraphQL gem, but it works with AnyCable. The motivation is that AnyCable is fast because it executes no Ruby code, while the default subscription implementation requires re evaluating GraphQL queries in the Action Cable process, which AnyCable does not support well. The gem is built by Evil Martians, an American design and engineering consultancy for developer tools, AI and cybersecurity startups. The README links to an issue discussion for the deeper rationale. The result is a subscription layer that fits AnyCable's architecture instead of fighting it, keeping query execution in the process that triggers the event such as a web server, async job or rake task.
How it works and installs
Subscription information is stored in a Redis database, using AnyCable's Redis configuration by default, with expiration or cleanup configured separately. Installation adds the gem to the Gemfile with a version constraint around 1.0 and runs bundle install. Usage plugs the adapter into the schema with a use statement enabling broadcast, defines a channel that executes queries and transmits results, and triggers events as usual through the schema's subscriptions trigger method with optional scope. When using a non Redis AnyCable broadcasting adapter, the user must configure Redis for graphql anycable explicitly, either with a single connection or a connection pool. The gem works with Action Cable for development and test and works without Rails through LiteCable.
Broadcasting and licensing
By default the gem evaluates queries and transmits results for every subscription client individually, which wastes resources when many clients subscribe to the same data. GraphQL Ruby's Subscriptions Broadcast feature groups identical subscriptions, executes them once and transmits results once, and it is enabled by passing the broadcast option set to true. All fields are marked not safe for broadcasting by default, and if a subscription has at least one non broadcastable field, GraphQL Ruby executes every subscription independently; a default broadcastable option can be set to true if the user is sure all fields are safe, with a warning about security implications. The repository carries 114 stars and 20 forks with 10 open issues, the default branch is master, and the license is MIT.
Editorial conclusion
GraphQL AnyCable is an MIT licensed Ruby gem on the master branch with 114 stars built by Evil Martians that replaces the GraphQL gem's ActionCable subscription adapter with a Redis backed, AnyCable compatible implementation, and it supports broadcast grouping to avoid redundant query execution across many clients.
Community notes