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



31
32
33
34
35
36
37
38
# File 'lib/graphql/pagination/active_record_relation_connection.rb', line 31

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
16
17
18
19
20
21
# File 'lib/graphql/pagination/active_record_relation_connection.rb', line 8

def relation_count(relation)
  int_or_hash = if relation.respond_to?(:unscope)
    relation.unscope(:order).count(:all)
  else
    # Rails 3
    relation.count
  end
  if int_or_hash.is_a?(Integer)
    int_or_hash
  else
    # Grouped relations return count-by-group hashes
    int_or_hash.length
  end
end

#relation_limit(relation) ⇒ Object



23
24
25
# File 'lib/graphql/pagination/active_record_relation_connection.rb', line 23

def relation_limit(relation)
  relation.limit_value
end

#relation_offset(relation) ⇒ Object



27
28
29
# File 'lib/graphql/pagination/active_record_relation_connection.rb', line 27

def relation_offset(relation)
  relation.offset_value
end