-
-
Notifications
You must be signed in to change notification settings - Fork 848
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
fix(jsonapi): add support for pagination array parameter name #6319
base: main
Are you sure you want to change the base?
fix(jsonapi): add support for pagination array parameter name #6319
Conversation
src/State/Pagination/Pagination.php
Outdated
* page[page] => $contextFilters['page'] with default configuration page_parameter_name: page | ||
* page[number] => $contextFilters['_page'][number] with configuration page_parameter_name: page[number]. | ||
*/ | ||
private function extractParameter(array $contextFilters, string $parameterName) |
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.
missing return type
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.
i've added mixed, but not very top
/** | ||
* Extract pagination parameter | ||
* page[page] => $contextFilters['page'] with default configuration page_parameter_name: page | ||
* page[number] => $contextFilters['_page'][number] with configuration page_parameter_name: page[number]. |
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.
you mean that you configure page[number]
on the page_parameter_name
, then you use page[number]=1
?
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.
Yeah exactly
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.
To add more context to this, JSON:API consider query parameter such as two parameters named page[offset]
and page[limit]
really are two separate parameters, instead of a single page parameter in an array form.
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.
Yeah or page[number]
& page[size]
in my implementation if you work with page numbers instead of offset/limit cf https://jsonapi.org/format/#fetching-pagination
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.
can you add a function test and a unit test?
/** | ||
* Extract pagination parameter | ||
* page[page] => $contextFilters['page'] with default configuration page_parameter_name: page | ||
* page[number] => $contextFilters['_page'][number] with configuration page_parameter_name: page[number]. |
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.
can you add a function test and a unit test?
@@ -219,13 +219,38 @@ private function getGraphQlEnabled(?Operation $operation): bool | |||
return $operation?->getPaginationEnabled() ?? $enabled; | |||
} | |||
|
|||
/** | |||
* Extract pagination parameter |
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.
The pagination parameter value?
*/ | ||
private function extractParameter(array $contextFilters, string $parameterName): mixed | ||
{ | ||
preg_match_all("/[\w-]+/", $parameterName, $matches); |
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.
I don't understand the need of this regex here, we know the possible parameter names no? I'd love a test to understand this better.
@soyuka If you've time to check the unit test to better understand the use case. |
This bugfix is related to the jsonapi spec & the handling of pagination parameters in the pagination service.
Following the JSON:API specification around pagination => https://jsonapi.org/format/#fetching-pagination
When i setup api_platform.yaml with
And use ApiPlatform\State\Pagination\Pagination in a custom provider, we can't retrieve the
page[number]
&page[size]
in$context['filters']
.Thanks to @GregoireHebert for the help.
In addition this fix that let us specify array in pagination parameter names will fix the generated documentation.