Class: Taro::Types::ObjectTypes::PageWithTotalCountType

Inherits:
PageType show all
Defined in:
lib/taro/types/object_types/page_with_total_count_type.rb

Overview

This is an expanded ‘PageType` that adds a `total_count` field to show the total number of records in the paginated relation. It is not recommended for very large relations where counting might be slow.

Usage:

  • ‘returns code: :ok, page_with_total_count_of: ’UserType’‘

  • ‘UserType.page_with_total_count.render(User.all, after: params)`

The gem rails_cursor_pagination must be installed to use this.

Instance Attribute Summary

Attributes included from Shared::ItemType

#item_type

Class Method Summary collapse

Methods inherited from PageType

render

Methods included from Shared::ItemType

#raise_mixed_types

Methods inherited from ResponseType

#coerce_input

Methods included from Shared::Fields

#field, #fields

Methods included from Shared::ObjectCoercion

#coerce_input, #coerce_response

Methods included from Shared::CustomFieldResolvers

included, #resolve?

Class Method Details

.default_openapi_nameObject



21
22
23
# File 'lib/taro/types/object_types/page_with_total_count_type.rb', line 21

def self.default_openapi_name
  "#{item_type.openapi_name}_PageWithTotalCount"
end

.derive_from(from_type) ⇒ Object



12
13
14
15
# File 'lib/taro/types/object_types/page_with_total_count_type.rb', line 12

def self.derive_from(from_type)
  super
  field(:total_count, type: 'Integer', null: false)
end

.paginate(relation) ⇒ Object



17
18
19
# File 'lib/taro/types/object_types/page_with_total_count_type.rb', line 17

def self.paginate(relation, **)
  super.merge(total_count: relation.count)
end