Class: GraphQL::Pagination::ActiveRecordRelationConnection

Inherits:
RelationConnection show all
Defined in:
lib/graphql/pagination/active_record_relation_connection.rb

Overview

Customizes RelationConnection to work with ActiveRecord::Relations.

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 RelationConnection

#cursor_for, #has_next_page, #has_previous_page, #nodes

Methods inherited from Connection

#after, #before, #cursor_for, edge_class, #edge_nodes, #edges, #end_cursor, #has_next_page, #has_previous_page, #initialize, #nodes, #page_info, #start_cursor

Constructor Details

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

Instance Method Details

#null_relation(relation) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/graphql/pagination/active_record_relation_connection.rb', line 25

def null_relation(relation)
  if relation.respond_to?(:none)
    relation.none
  else
    # Rails 3
    relation.where("1=2")
  end
end

#relation_count(relation) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/graphql/pagination/active_record_relation_connection.rb', line 8

def relation_count(relation)
  if relation.respond_to?(:unscope)
    relation.unscope(:order).count(:all)
  else
    # Rails 3
    relation.count
  end
end

#relation_limit(relation) ⇒ Object



17
18
19
# File 'lib/graphql/pagination/active_record_relation_connection.rb', line 17

def relation_limit(relation)
  relation.limit_value
end

#relation_offset(relation) ⇒ Object



21
22
23
# File 'lib/graphql/pagination/active_record_relation_connection.rb', line 21

def relation_offset(relation)
  relation.offset_value
end