Class: GraphQL::Connections::PrimaryKey::Base
- Defined in:
- lib/graphql/connections/primary_key/base.rb
Overview
Base class for PrimaryKey pagination implementations
Direct Known Subclasses
Constant Summary collapse
- COMPARABLE_METHODS =
%i[ gt lt lteq gteq ].freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #cursor_for(item) ⇒ Object
- #has_next_page ⇒ Object
- #has_previous_page ⇒ Object
-
#initialize(*args, primary_key: nil, **kwargs) ⇒ Base
constructor
A new instance of Base.
Methods inherited from Base
Constructor Details
#initialize(*args, primary_key: nil, **kwargs) ⇒ Base
Returns a new instance of Base.
12 13 14 15 16 |
# File 'lib/graphql/connections/primary_key/base.rb', line 12 def initialize(*args, primary_key: nil, **kwargs) @primary_key = primary_key super(*args, **kwargs) end |
Instance Method Details
#cursor_for(item) ⇒ Object
42 43 44 45 46 |
# File 'lib/graphql/connections/primary_key/base.rb', line 42 def cursor_for(item) cursor = serialize(item[primary_key]) cursor = encode(cursor) if opaque_cursor cursor end |
#has_next_page ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/graphql/connections/primary_key/base.rb', line 30 def has_next_page return false if nodes.empty? if first items_exist?(type: :query, search: nodes.last[primary_key], page_type: :next) elsif before items_exist?(type: :cursor, search: before_cursor, page_type: :next) else false end end |
#has_previous_page ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/graphql/connections/primary_key/base.rb', line 18 def has_previous_page return false if nodes.empty? if last items_exist?(type: :query, search: nodes.first[primary_key], page_type: :previous) elsif after items_exist?(type: :cursor, search: after_cursor, page_type: :previous) else false end end |