Class: GraphQL::Relay::RelationConnection

Inherits:
BaseConnection show all
Defined in:
lib/graphql/relay/relation_connection.rb

Overview

A connection implementation to expose SQL collection objects. It works for:

  • ActiveRecord::Relation
  • Sequel::Dataset

Constant Summary

Constants inherited from BaseConnection

BaseConnection::CONNECTION_IMPLEMENTATIONS, BaseConnection::CURSOR_SEPARATOR, BaseConnection::METHODS_FROM_ARGUMENTS

Instance Attribute Summary

Attributes inherited from BaseConnection

#arguments, #field, #max_page_size, #nodes, #parent

Instance Method Summary collapse

Methods inherited from BaseConnection

#after, #before, connection_for_nodes, #decode, #edge_nodes, #encode, #end_cursor, #first, #initialize, #last, #page_info, register_connection_implementation, #start_cursor

Constructor Details

This class inherits a constructor from GraphQL::Relay::BaseConnection

Instance Method Details

#cursor_from_node(item) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/graphql/relay/relation_connection.rb', line 9

def cursor_from_node(item)
  item_index = paged_nodes_array.index(item)
  if item_index.nil?
    raise("Can't generate cursor, item not found in connection: #{item}")
  else
    offset = starting_offset + item_index + 1
    encode(offset.to_s)
  end
end

#has_next_pageObject



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

def has_next_page
  !!(first && sliced_nodes.limit(limit + 1).count > limit)
end

#has_previous_pageObject



23
24
25
# File 'lib/graphql/relay/relation_connection.rb', line 23

def has_previous_page
  !!(last && starting_offset > 0)
end