Class: Types::BaseConnection
- Inherits:
-
BaseObject
- Object
- BaseObject
- Types::BaseConnection
- Includes:
- GraphQL::Types::Relay::ConnectionBehaviors
- Defined in:
- app/graphql/types/base_connection.rb,
lib/generators/cm_graphql/templates/base_connection.rb
Instance Method Summary collapse
Instance Method Details
#total_count ⇒ Object
7 8 9 |
# File 'app/graphql/types/base_connection.rb', line 7 def total_count object.nodes&.count end |
#total_page_count ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/graphql/types/base_connection.rb', line 12 def total_page_count return 1 unless object.nodes&.count&.positive? # get total count and create array with total count as first item my_total_count = object.nodes&.count possible_page_sizes = [my_total_count] # add first and last argument counts to the array if they exist possible_page_sizes.push(object.arguments[:first]) if object.arguments[:first] possible_page_sizes.push(object.arguments[:last]) if object.arguments[:last] # get the smallest of the array items actual_page_size = possible_page_sizes.min # return the total_count divided by the page size, rounded up (my_total_count / actual_page_size.to_f).ceil end |