class GraphqlRails::Model::BuildConnectionType::CountItems

Used when generating ConnectionType. It handles all the logic which is related with counting total items

Attributes

graphql_object[R]

Public Class Methods

new(graphql_object) click to toggle source
# File lib/graphql_rails/model/build_connection_type/count_items.rb, line 13
def initialize(graphql_object)
  @graphql_object = graphql_object
end

Public Instance Methods

call() click to toggle source
# File lib/graphql_rails/model/build_connection_type/count_items.rb, line 17
def call
  if active_record?
    list.except(:offset).size
  else
    list.size
  end
end

Private Instance Methods

active_record?() click to toggle source
# File lib/graphql_rails/model/build_connection_type/count_items.rb, line 33
def active_record?
  defined?(ActiveRecord) && list.is_a?(ActiveRecord::Relation)
end
list() click to toggle source
# File lib/graphql_rails/model/build_connection_type/count_items.rb, line 29
def list
  graphql_object.items
end