Class: Taro::Types::ObjectTypes::PageType
Overview
Abstract base class for Page types (paginated ActiveRecord data). Unlike other types, this one should not be manually inherited from, but is used indirectly via ‘page_of: SomeType`.
The gem rails_cursor_pagination must be installed to use this.
Instance Attribute Summary
#item_type
Class Method Summary
collapse
raise_mixed_types
#coerce_input
#field, #fields
#coerce_input, #coerce_response
included, #resolve?
Class Method Details
.default_openapi_name ⇒ Object
28
29
30
|
# File 'lib/taro/types/object_types/page_type.rb', line 28
def self.default_openapi_name
"#{item_type.openapi_name}_Page"
end
|
.derive_from(from_type) ⇒ Object
10
11
12
13
14
|
# File 'lib/taro/types/object_types/page_type.rb', line 10
def self.derive_from(from_type)
super
field(:page, array_of: from_type.name, null: false)
field(:page_info, type: 'Taro::Types::ObjectTypes::PageInfoType', null: false)
end
|
.paginate(relation, after:, limit: 20, order_by: nil, order: nil) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/taro/types/object_types/page_type.rb', line 20
def self.paginate(relation, after:, limit: 20, order_by: nil, order: nil)
result = RailsCursorPagination::Paginator.new(
relation, limit:, order_by:, order:, after:
).fetch
result[:page].map! { |el| el.fetch(:data) }
result
end
|
.render(relation) ⇒ Object
16
17
18
|
# File 'lib/taro/types/object_types/page_type.rb', line 16
def self.render(relation, **)
super(paginate(relation, **))
end
|