Class: GraphQR::Pagination::Resolvers::PagyResolver
- Inherits:
-
Object
- Object
- GraphQR::Pagination::Resolvers::PagyResolver
- Includes:
- Pagy::Backend
- Defined in:
- lib/graphqr/pagination/resolvers/pagy_resolver.rb
Overview
This is a resolver that uses ‘Pagy::Backend` and maps it to the GraphQL pagination structure.
Instance Method Summary collapse
- #cursor_from_node(item) ⇒ Object
- #edge_nodes ⇒ Object
- #edges ⇒ Object
-
#initialize(records, arguments) ⇒ PagyResolver
constructor
A new instance of PagyResolver.
- #nodes ⇒ Object
- #page_info ⇒ Object
Constructor Details
#initialize(records, arguments) ⇒ PagyResolver
Returns a new instance of PagyResolver.
11 12 13 14 15 16 17 |
# File 'lib/graphqr/pagination/resolvers/pagy_resolver.rb', line 11 def initialize(records, arguments) @records = records @arguments = arguments @pagy, paginated_records = pagy(records, arguments) @paginated_records = paginated_records.to_a end |
Instance Method Details
#cursor_from_node(item) ⇒ Object
19 20 21 |
# File 'lib/graphqr/pagination/resolvers/pagy_resolver.rb', line 19 def cursor_from_node(item) item.to_global_id.to_s end |
#edge_nodes ⇒ Object
23 24 25 |
# File 'lib/graphqr/pagination/resolvers/pagy_resolver.rb', line 23 def edge_nodes @paginated_records end |
#edges ⇒ Object
31 32 33 |
# File 'lib/graphqr/pagination/resolvers/pagy_resolver.rb', line 31 def edges @paginated_records end |
#nodes ⇒ Object
27 28 29 |
# File 'lib/graphqr/pagination/resolvers/pagy_resolver.rb', line 27 def nodes @paginated_records end |
#page_info ⇒ Object
35 36 37 |
# File 'lib/graphqr/pagination/resolvers/pagy_resolver.rb', line 35 def page_info @pagy end |