-
Notifications
You must be signed in to change notification settings - Fork 77
Reimplementing pagination #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
After some thought, I think pagination strategies do not belong into the serializer. The JSONAPI spec does not mandate any particular strategy, it just reserves the use of the So, my latest commit provides an extensible behavior for dealing with pagination which basically boils down to delegating pagination links to the view The deafult implementation of the function provides no links, unless a An implementation of a page-based strategy is implemented. Tests are updated and demonstrate the usage. I think this improves on the previous iteration, thoughts? |
Sorry for missing this PR @lucacorti! We'll get eyes on it this week and let you know our thoughts, thanks for getting involved 😁 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good @lucacorti! Some comments and thoughts on the code so far
The failing test esposes a bug (#191) in the QueryParser, which ends up populating the JSONAPI.Page struct with string values from the query parametes, which in turn break the paginator which expects integers as per |
Hey friends. Sorry for taking so long to get to this. Life, etc. I haven't used the current pagination support, so I have some background questions:
|
JSON API mandates the use of the The main problem with the current implementation from my point of view is everything is done into the links callback and doesn't offer much flexibility. In my opinion the links callback is a good place to address custom links, while being able to delegate pagination to a different module allows to define a clear interface, configure pagination at project/view level and possibly override the pagination_links for even more flexibility. So IMHO basic pagination support belongs in the project, specific pagination implementations maybe not. Another thing I'd like to add to my PR to go down the spec compliance route even more is allowing the user to specify which query params map to which |
Latest commit fixes #191 and adds support for custom query parameters for pagination via
For all pagination query params inside |
Generally speaking I feel like this PR needs to be approached slightly differently. Currently:
I know this will be more work and it's a lot to ask from someone freely contributing their time, but I'd like to see an alternate approach.
|
Also I gave some more thought about the upgrade path and realized my PR already addresses this in a backwards compatible way. Pagination links currently generated in the view I guess properly documenting this behavior and how to migrate to the new one should be enough. |
JSONAPI.Page
to the serializer
So, I'd like to recap where I'm trying to go with this PR. The current implementation has a few issues:
What this PR does:
What is missing to complete the work
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few quick notes above. The one thing I'm really uncertain about is what a Paginator
is or does. Is it the thing that actually does the paginating, or is that done by something else? If the latter, perhaps we should document it, or add a smoke test for it?
How hard would it be to resolve the issues in #131 using your implementation? |
@jherdman About the This is why options are passed back from the controller to the paginator module in form of options, to pass back information from the pagination process needed to generate links. |
@jherdman I've updated the tests and added documentation. I think this is quite complete. Anything else we need to address? |
@lucacorti LGTM! It needs a rebase, but I'd love to get @doomspork or @snewcomer 's eyes on it too. |
This implements page/offset/cursor pagination strategies in the serializer
Don't try and parse query params into a struct, just copy over the query parameters and delegate link generation completely tyo the paginator
@jherdman / @lucacorti this looks good to me. Thank you both for putting in so much time to get this across the finish line. |
@jherdman @doomspork Thank you for bearing with me while I was iterating on the implementation. |
Thank you @lucacorti for doing that. It's truly awesome to have open source contributors like you, I cannot stress enough how much we value people like yourself. I hope you'll continue your contributions 😁 |
This implements page/offset/cursor pagination strategies in the serializer by passing a
JSONAPI.Page
object to theserialize
function and implementing basic page, offset and cursor strategies. It also gets rid of the now uselesswith_pagination
knob.