Problem/Motivation
Follow-up from #2793233: [FEATURE] Respect the provided maximum page[limit] value
Currently amount of items per page is capped by 50 items. There is a good reason behind this decisionl (see parent issue), however certain cases still require this value to be changed. Since JSON API is zero configuration module, the best place to implement the configuration is JSON API Extras.
Proposed resolution
Provide configuration which allows backend developers to easily configure max value of page[limit] per entity per bundle.
Comments
Comment #2
spleshkaAssigning to myself
Comment #3
spleshkaComment #4
e0ipsoLowering priority on this.
Comment #5
spleshkaStill hoping to resolve this issue, but unassigning myself, because I couldn't find time for this within the last 1.5 months. Let's open this issue for other contributors and see if someone can beat me :)
Comment #6
e0ipsoI'm closing this as part of issue queue cleanup. Please reopen if necessary.
Comment #7
moshe weitzman commentedIts needed on a project of mine (mass.gov())
Comment #8
e0ipsoThanks for picking this one up Moshe.
Comment #9
moshe weitzman commentedI made a new module - https://www.drupal.org/project/jsonapi_page_limit. If folks prefer this functionality in Extras thats fine with me.
Comment #10
s_leu commentedI created a patch the moves the functionality moshe implemented in https://www.drupal.org/project/jsonapi_page_limit into this module, as jsonapi_page_limit doesn't work when jsonapi_extras is available. Also having this configurable on the UI via a textfield makes this configuration easier.
Happy to improve the patch if there's anything to improve.
Comment #11
s_leu commentedComment #12
s_leu commentedForgot a closing tag and improved the field description slightly. Couldn't use the "upload" button here in the form, thus loading up the patch for #11 in a separate post, the interdiff is in comment #11.
Comment #13
s_leu commentedAnother typo in the field description...
Comment #14
luksakSetting a limit for a bundle broke pagination for me. Right now I dont know what is going wrong, but i assume that it always outputs a next page link without an appropriate offset and therefore has infinite pages :)
Comment #15
s_leu commentedThanks for checking the patch. I've fixed the issue with pagination and added a test for it as well. Here's the new patch
Comment #16
bbralaThanks for taking the time to get this working :)
I found some time to test this and found some issues that need to be resolved.
We can set the limit to a lower value than the jsonapi module. This will break things, since it will then limit the results on all pages EXCEPT the first one.
I would probably make this an method.
Doesn't this mean we now only test with an higher limit? If so, rather we not do that.
Should this also test setting the limit to something higter than the limit and check if that doesn't work?
Comment #17
s_leu commentedThanks for the review @bbrala. Made the suggested improvements, here's the new patch.
Comment #18
bbralaThanks! Tested and seems like it is good to go :)
Comment #21
gowda_mohan commentedCan anyone please let me know how to patch the submodules jsonapi_extras/jsonapi_defaults? I tried the following to no avail:
"extra": {
"patches": {
"drupal/jsonapi_extras" : {
"Configurable JSON:API Max Limit": "https://www.drupal.org/files/issues/2020-08-09/max-page-limit-configurab..."
}
},
Output:
$ composer update
Gathering patches for root package.
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Comment #22
bbralaLatest version has this feature merged, are you running the latest version?
Comment #23
drupalninja99 commentedSo I installed the module and configured 1000 max for all my overridden resources. I am still seeing that on all the JSON requests they are not using the overridden value but are instead using the default "50" limit. I have poked around but I need a line of code to zoom in on to see where the "overridden" value is being lost in the handoffs from one method to another.
Comment #24
dishabhadra commentedI installed the latest version of the module and set the page limit configuration in the overridden resources. All the JSON requests using the default limit of "50", page limit configuration not working as expected.
I debugged the code and fixed the issue. Created the patch for the same.
I covered the below scenarios,
.
Please review my patch.
Comment #25
jithenderc commented@dishabadra Hi, I am trying to apply your patch on the drupal core but getting exceptions while doing it. I am using drupal core 8.
Comment #26
bbralaOk this seems to need some work then... reopening.
Comment #27
theruslan@dishabhadra thanks for your work!
But patch from #24 doesn't work on Drupal 9.3.9 / PHP 7.4.28 (UPD: and on PHP 8.1.3)
Comment #28
mogio_hh commentedI can confirm, that page[limit] cannot be set via the module.
Is the field in the jsonapi defaults module just buggy or was this never implemented correctly?
Comment #29
mogio_hh commentedI can confirm, that page[limit] cannot be set via the module.
Is the field in the jsonapi defaults module just buggy or was this never implemented correctly?
admin: Please remove the double post. thanks
Comment #30
dan_rogersFor anyone looking and/or confused, this is in the "JSON API Defaults" submodule. It must be enabled in order to be set via the UI.
Even then, it is set per endpoint, in the "Resource Ovverides" tab, in the "Collection" fieldset > Page limit.
Even after set, I had to manually specify my limit in the actual call as well, ie `&page%5Blimit%5D=200`.
Hope this helps someone.
Comment #31
danishkshah commentedI can confirm the Patch #24 is not working. I have enabled "JSON API Defaults" submodule. Overwritten the resource by setting the page limit. Even after manually specifying the limit above the set page limit. It is still returning 50 records only.
Comment #32
pingwin4egNote that the jsonapi_defaults conflicts with the next_jsonapi module. Both try to alter the jsonapi.entity_resource controller/service.
In my case next_jsonapi's controller works and jsonapi_defaults' doesn't, this in turn doesn't enable the page limit change from the module.
Comment #33
mayurngondhkarReroll patch
Comment #34
bbralaCan you please also attach an interdiff? You can read how here: creating-an-interdiff
Comment #35
rishabh vishwakarma commentedAdded a patch for Drupal 9
Comment #36
jaykainthola commentedI have tested patch #35 and it's working fine. Now, its taking configuration of resource for page limit.