Created
June 21, 2018 07:30
-
-
Save MatteoJoliveau/df3d51fcecb446f62f2fc0f185cde60b to your computer and use it in GitHub Desktop.
Pageable interface to paginate with Kaminari in GraphQL Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Types | |
module PageableType | |
include Types::Base::Interface | |
field :current_page, Integer, null: true | |
field :previous_page, Integer, null: true, method: :prev_page | |
field :next_page, Integer, null: true | |
field :total_pages, Integer, null: true | |
field :total_items, Integer, null: true, method: :total_count | |
field :size, Integer, null: true, method: :count | |
field :first_page, Boolean, null: true, method: :first_page? | |
field :last_page, Boolean, null: true, method: :last_page? | |
end | |
end | |
Hi guys, sorry I didn't notice the notification.
@Shaglock totally nailed the solution, and the interface is indeed meant to be compatible with Kaminari-like pagination libraries.
Implementing items
in a BaseCollection
that extends BaseObject
is a wonderful idea to keep code DRY.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Really appreciate you mentioning this! I ended up coming up with my own solution (using a proxy class to expose the kaminari AR object methods as GQL fields)
But maybe this will help someone else in the future who finds this.