Class: Types::CountableConnectionType

Inherits:
GraphQL::Types::Relay::BaseConnection
  • Object
show all
Defined in:
app/graphql/types/countable_connection_type.rb

Overview

rubocop: disable Graphql/AuthorizeTypes

Instance Method Summary collapse

Instance Method Details

#countObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/graphql/types/countable_connection_type.rb', line 9

def count
  # rubocop: disable CodeReuse/ActiveRecord
  relation = object.items

  # sometimes relation is an Array
  relation = relation.reorder(nil) if relation.respond_to?(:reorder)
  # rubocop: enable CodeReuse/ActiveRecord

  if relation.try(:group_values)&.present?
    relation.size.keys.size
  else
    relation.size
  end
end