Class: Taro::Types::ObjectTypes::PageWithTotalCountType
- Inherits:
-
PageType
- Object
- BaseType
- Taro::Types::ObjectType
- ResponseType
- PageType
- Taro::Types::ObjectTypes::PageWithTotalCountType
- 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
Class Method Summary collapse
Methods inherited from PageType
Methods included from Shared::ItemType
Methods inherited from ResponseType
Methods included from Shared::Fields
Methods included from Shared::ObjectCoercion
#coerce_input, #coerce_response
Methods included from Shared::CustomFieldResolvers
Class Method Details
.default_openapi_name ⇒ Object
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 |