Class: Taro::Types::ObjectTypes::PageType

Inherits:
ResponseType show all
Extended by:
Shared::ItemType
Defined in:
lib/taro/types/object_types/page_type.rb

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

Attributes included from Shared::ItemType

#item_type

Class Method Summary collapse

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



26
27
28
# File 'lib/taro/types/object_types/page_type.rb', line 26

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

.render(relation, after:, limit: 20, order_by: nil, order: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/taro/types/object_types/page_type.rb', line 16

def self.render(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) }

  super(result)
end