Method: Types::CountableConnectionType#count

Defined in:
app/graphql/types/countable_connection_type.rb

#count(limit: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/graphql/types/countable_connection_type.rb', line 17

def count(limit: nil)
  relation = object.items

  if limit
    # Limited counting for performance
    limited_count(relation, limit)
  else
    # Existing unlimited counting logic
    # sometimes relation is an Array
    relation = relation.without_order if relation.respond_to?(:reorder)

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