Module: GraphQL::Connections::Stable
- Defined in:
- lib/graphql/connections/stable.rb
Overview
Cursor-based pagination to work with ‘ActiveRecord::Relation`s. Implements a mechanism for serving stable connections based on column values. If objects are created or destroyed during pagination, the list of items won’t be disrupted.
Inspired by ‘GraphQL::Pro`s Stable Relation Connections graphql-ruby.org/pagination/stable_relation_connections.html
For more information see GraphQL Cursor Connections Specification relay.dev/graphql/connections.htm
Class Method Summary collapse
Class Method Details
.new(*args, desc: false, keys: nil, **kwargs) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/graphql/connections/stable.rb', line 15 def self.new(*args, desc: false, keys: nil, **kwargs) if kwargs[:primary_key] || keys.nil? cls = desc ? GraphQL::Connections::PrimaryKey::Desc : GraphQL::Connections::PrimaryKey::Asc return cls.new(*args, **kwargs) end raise ArgumentError, "keyset for more that 2 keys is not implemented yet" if keys.length > 2 klass = desc ? GraphQL::Connections::Keyset::Desc : GraphQL::Connections::Keyset::Asc klass.new(*args, **kwargs.merge(keys: keys)) end |