Class: GraphitiGql::Schema::Connection
- Inherits:
-
GraphQL::Pagination::Connection
- Object
- GraphQL::Pagination::Connection
- GraphitiGql::Schema::Connection
- Defined in:
- lib/graphiti_gql/schema/connection.rb
Direct Known Subclasses
Instance Method Summary collapse
- #cursor_for(item) ⇒ Object
- #has_next_page ⇒ Object
- #has_previous_page ⇒ Object
- #nodes ⇒ Object
- #proxy ⇒ Object
Instance Method Details
#cursor_for(item) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/graphiti_gql/schema/connection.rb', line 28 def cursor_for(item) nodes starting_offset = 0 page_param = proxy.query.pagination if (page_number = page_param[:number]) page_size = page_param[:size] || proxy.resource.default_page_size starting_offset = (page_number - 1) * page_size end if (cursor = page_param[:after]) starting_offset = cursor[:offset] end current_offset = @items.index(item) offset = starting_offset + current_offset + 1 # (+ 1 b/c o-base index) Base64.encode64({offset: offset}.to_json).chomp end |
#has_next_page ⇒ Object
21 22 23 24 25 26 |
# File 'lib/graphiti_gql/schema/connection.rb', line 21 def has_next_page nodes return false if @items.length.zero? cursor = JSON.parse(Base64.decode64(cursor_for(@items.last))) cursor["offset"] < @proxy.pagination.send(:item_count) end |
#has_previous_page ⇒ Object
17 18 19 |
# File 'lib/graphiti_gql/schema/connection.rb', line 17 def has_previous_page proxy.pagination.has_previous_page? end |
#nodes ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/graphiti_gql/schema/connection.rb', line 4 def nodes return @items if @run_once @proxy = @items.proxy @items = @items.data @run_once = true @items end |
#proxy ⇒ Object
12 13 14 15 |
# File 'lib/graphiti_gql/schema/connection.rb', line 12 def proxy nodes @proxy end |