Gem Version Build Status

GraphQL::Connections

Cursor-based pagination to work with ActiveRecord::Relations.

Implements Relay specification for serving stable connections based on column values. If objects are created or destroyed during pagination, the list of items won’t be disrupted.

Sponsored by Evil Martians

Installation

Add this line to your application's Gemfile:

gem "graphql-connections"

Usage

You can use a stable connection wrapper on a specific field:

field :messages, Types::Message.connection_type, null: false

def messages
  GraphQL::Connections::Stable.new(Message.all)
end

Or you can apply a stable connection to all Active Record relations returning by any field:

class ApplicationSchema < GraphQL::Schema
  use GraphQL::Pagination::Connections

  connections.add(ActiveRecord::Relation, GraphQL::Connections::Stable)
end

NOTE: Don't use stable connections for relations whose ordering is too complicated for cursor generation.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bibendi/graphql-connections.

License

The gem is available as open source under the terms of the MIT License.