-
Notifications
You must be signed in to change notification settings - Fork 15
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
Question on the default order of the cursor pagination implementation #40
Comments
One thing to note, is we need to make sure this works if the client has changed the sort order. For example, if the default was ascending, if the client sent a sort parameter of |
Hmmm... I am starting to wonder whether descending does actually make sense, considering an API client probably always wants the latest results on the first "page". I'm guessing that was your thinking? |
If a sort for key column is already applied to the query then the paginator won't add or change it, so this should work fine, probably good to explicitly have a test for it however. |
My thinking was to make it a drop in replacement for the existing cursor pagination, which in the absence of you specifying a column will sort desc on createdAt and then id by default. Assuming an incrementing or monotonic key this implementation will give the same sort out of the box without config. |
also if your in a merging mood on this package #38 😉 |
Yeah all great points - thank you. Will keep the descending order, think that makes sense. I think there's two things I need to do before tagging:
For (2) I'm not overly worried if there's something that is totally breaking. In theory an API could continue to use the current package then when they move to a new version introduce the new implementation. Alternatively, they would be able to exist side-by-side using the Would be useful though for me to know whether they can be set up in an identical way, or if we need to provide some sort of upgrade guide. Thanks for the nudge about #38, have added that to the project board so I stay on top of it. |
I think a very small upgrade-guide/warning would be good just to highlight the default sort behaviour being different really, as the rest of the API should be fully compatible. |
Help with the docs would be great! Means I'll have time to look at other JSON:API tickets including your other PR. I've created this issue in the docs repo: laravel-json-api/laravel-json-api.github.io#38 If it's too much for you to do all of it, just say and we can split up the tasks on that ticket. Really appreciate your help but don't want to put too much on you! |
Been going through it again tonight and we're looking really close to tagging. The only thing left for me to do is create the test case in the existing cursor pagination package to ensure it is backwards compatible. (With the caveat it's never backwards compatible if clients have been told they can just use any resource ID as the before/after cursor position.) |
That all sounds sensible, I will make a start and keep you updated. I am happy to give something back since I have used this package for many years in a number or roles. |
Unfortunately run out of time to finish this off tonight. I'll prioritise it next time I'm on JSON:API things, which will probably be at the weekend. |
Had a play around with the tests in the Decided it's not the best use of my time trying to get the tests working. I think we can provide broad advice that it should be a drop in replacement if you add a |
@haddowg I've tagged the cursor pagination in the Eloquent package as Great to get it out and thanks for all your hard work on it! I'll announce it once we've sorted out the docs. |
@haddowg The cursor pagination implementation looks great, but I have a question around the sort order that we need to resolve before I tag - because once I tag, any changes would be breaking.
From the description to #37 -
Question: Should it be descending by default?
When you do this in Eloquent:
You get posts in ascending order, not descending order. It took me be surprise when reviewing the tests as it felt like the default order was the wrong way round.
So the question is, should the order be ascending by default? So that it matches Eloquent, which feels more predictable from a DX perspective. Then use a
withDescending()
method if the developer wants to change the default?The text was updated successfully, but these errors were encountered: