Class: GraphQL::Pagination::RelationConnection
- Inherits:
-
Pagination::Connection
- Object
- Pagination::Connection
- GraphQL::Pagination::RelationConnection
- Defined in:
- lib/graphql/pagination/relation_connection.rb
Overview
A generic class for working with database query objects.
Instance Method Summary collapse
- #cursor_for(item) ⇒ Object
-
#cursor_for_position(item, position) ⇒ Object
:nodoc:.
- #has_next_page ⇒ Object
- #has_previous_page ⇒ Object
- #nodes ⇒ Object
Instance Method Details
#cursor_for(item) ⇒ Object
60 61 62 63 64 |
# File 'lib/graphql/pagination/relation_connection.rb', line 60 def cursor_for(item) load_nodes position = cursor_index_for(item, nodes) offset_cursor_for_position(position) end |
#cursor_for_position(item, position) ⇒ Object
:nodoc:
66 67 68 69 70 71 72 |
# File 'lib/graphql/pagination/relation_connection.rb', line 66 def cursor_for_position(item, position) # :nodoc: if self.class.custom_cursor_for?(RelationConnection) super else offset_cursor_for_position(position) end end |
#has_next_page ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/graphql/pagination/relation_connection.rb', line 37 def has_next_page # If the query loads the page anyway, load it now so its extra row answers this if @has_next_page.nil? && peek_next_page? && (lookahead.selects?(:nodes) || lookahead.selects?(:edges) || page_info_selection.selects?(:start_cursor) || page_info_selection.selects?(:end_cursor)) load_nodes end if @has_next_page.nil? @has_next_page = if before_offset && before_offset > 0 true elsif first if @nodes && @nodes.count < first false else relation_larger_than(sliced_nodes, @sliced_nodes_offset, first) end else false end end @has_next_page end |
#has_previous_page ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/graphql/pagination/relation_connection.rb', line 20 def has_previous_page if @has_previous_page.nil? @has_previous_page = if after_offset && after_offset > 0 true elsif last # See whether there are any nodes _before_ the current offset. # If there _is no_ current offset, then there can't be any nodes before it. # Assume that if the offset is positive, there are nodes before the offset. limited_nodes !(@paged_nodes_offset.nil? || @paged_nodes_offset == 0) else false end end @has_previous_page end |
#nodes ⇒ Object
15 16 17 18 |
# File 'lib/graphql/pagination/relation_connection.rb', line 15 def nodes load_nodes @nodes end |