Class: GraphQL::Connections::Keyset::Asc
- Defined in:
- lib/graphql/connections/keyset/asc.rb
Overview
Implements keyset pagination by two fields with asc order
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Methods inherited from Base
#cursor_for, #initialize, #nodes, #primary_key
Constructor Details
This class inherits a constructor from GraphQL::Connections::Keyset::Base
Instance Method Details
#has_next_page ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/graphql/connections/keyset/asc.rb', line 27 def has_next_page if first nodes.any? && items.where(arel_table[field_key].eq(nodes.last[field_key])) .where(arel_table[primary_key].gt(nodes.last[primary_key])) .or(items.where(arel_table[field_key].gt(nodes.last[field_key]))) .exists? elsif before items .where(arel_table[field_key].gt(before_cursor_date)) .or( items.where(arel_table[field_key].eq(before_cursor_date)) .where(arel_table[primary_key].gt(before_cursor_primary_key)) ).exists? else false end end |
#has_previous_page ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/graphql/connections/keyset/asc.rb', line 8 def has_previous_page if last nodes.any? && items.where(arel_table[field_key].eq(nodes.first[field_key])) .where(arel_table[primary_key].lt(nodes.first[primary_key])) .or(items.where(arel_table[field_key].lt(nodes.first[field_key]))) .exists? elsif after items .where(arel_table[field_key].lt(after_cursor_date)) .or( items.where(arel_table[field_key].eq(after_cursor_date)) .where(arel_table[primary_key].lt(after_cursor_primary_key)) ).exists? else false end end |