Class: GraphQL::Pagination::RelationConnection

Inherits:
Connection
  • Object
show all
Defined in:
lib/graphql/pagination/relation_connection.rb

Overview

A generic class for working with database query objects.

Instance Attribute Summary

Attributes inherited from Connection

#after_value, #before_value, #context, #first, #first_value, #items, #last, #last_value, #max_page_size

Instance Method Summary collapse

Methods inherited from Connection

#after, #before, edge_class, #edge_nodes, #edges, #end_cursor, #initialize, #page_info, #start_cursor

Constructor Details

This class inherits a constructor from GraphQL::Pagination::Connection

Instance Method Details

#cursor_for(item) ⇒ Object



23
24
25
26
27
28
# File 'lib/graphql/pagination/relation_connection.rb', line 23

def cursor_for(item)
  load_nodes
  # index in nodes + existing offset + 1 (because it's offset, not index)
  offset = nodes.index(item) + 1 + (@paged_nodes_offset || 0) + (relation_offset(items) || 0)
  context.schema.cursor_encoder.encode(offset.to_s)
end

#has_next_pageObject



18
19
20
21
# File 'lib/graphql/pagination/relation_connection.rb', line 18

def has_next_page
  load_nodes
  @has_next_page
end

#has_previous_pageObject



13
14
15
16
# File 'lib/graphql/pagination/relation_connection.rb', line 13

def has_previous_page
  load_nodes
  @has_previous_page
end

#nodesObject



8
9
10
11
# File 'lib/graphql/pagination/relation_connection.rb', line 8

def nodes
  load_nodes
  @nodes
end