Skip to content

Instantly share code, notes, and snippets.

@lewisvoncken
Last active October 6, 2021 08:17
Show Gist options
  • Save lewisvoncken/a10d2856966084243ff0ab336d503247 to your computer and use it in GitHub Desktop.
Save lewisvoncken/a10d2856966084243ff0ab336d503247 to your computer and use it in GitHub Desktop.

Magento Rest/GraphQl API Ratelimit Extend Patch

source:

To apply the patch using Composer:

  1. Open your command line application and navigate to your project directory
  2. Add the cweagans/composer-patches plugin to the composer.json file.
  composer require cweagans/composer-patches
  1. Edit the `composer.json file and add the following section to specify:
    • Module: magento/magento2-base
    • Title: MC-43048 set ratelimit
    • Patch to patch: https://gist.githubusercontent.com/lewisvoncken/a10d2856966084243ff0ab336d503247/raw/MC-43048__set_rate_limits__2.4.3.patch or https://gist.githubusercontent.com/lewisvoncken/a10d2856966084243ff0ab336d503247/raw/MC-43048__set_rate_limits__2.3.7-p1.patch

For example (2.3.7-p1):

  "extra": {
      "composer-exit-on-patch-failure": true,
      "patches": {
          "magento/magento2-base": {
              "MC-43048 set ratelimit": "https://gist.githubusercontent.com/lewisvoncken/a10d2856966084243ff0ab336d503247/raw/MC-43048__set_rate_limits__2.3.7-p1.patch"
          }
      }
  }

For example (2.4.3):

  "extra": {
      "composer-exit-on-patch-failure": true,
      "patches": {
          "magento/magento2-base": {
              "MC-43048 set ratelimit": "https://gist.githubusercontent.com/lewisvoncken/a10d2856966084243ff0ab336d503247/raw/MC-43048__set_rate_limits__2.4.3.patch"
          }
      }
  }
  1. Apply the patch. Use the -v option only if you want to see debugging information.
# Dev
composer install -v
# Production:
composer install --no-dev
  1. optional Update the composer.lock file. The lock file tracks which patches have been applied to each Composer package in an object.
composer update --lock

IMPORTANT

DI COMPILE

The patch is applied to a di.xml file so when applying it manually in production mode it requires a deployment/re-compile

php bin/magento setup:di:compile

version controll

Perhaps the app/etc/di.xml / composer.json / composer.lock is added through version control than also commit & push.

diff --git a/app/etc/di.xml b/app/etc/di.xml
index ace043beb62..7751604ea1d 100644
--- a/app/etc/di.xml
+++ b/app/etc/di.xml
@@ -1896,12 +1896,12 @@
</type>
<type name="Magento\Framework\Webapi\Validator\EntityArrayValidator">
<arguments>
- <argument name="complexArrayItemLimit" xsi:type="number">20</argument>
+ <argument name="complexArrayItemLimit" xsi:type="number">999999</argument>
</arguments>
</type>
<type name="Magento\Framework\Webapi\Validator\SearchCriteriaValidator">
<arguments>
- <argument name="maximumPageSize" xsi:type="number">300</argument>
+ <argument name="maximumPageSize" xsi:type="number">999999</argument>
</arguments>
</type>
<preference for="Magento\Framework\GraphQl\Query\Resolver\Argument\ValidatorInterface" type="Magento\Framework\GraphQl\Query\Resolver\Argument\Validator\CompositeValidator"/>
@@ -1914,7 +1914,7 @@
</type>
<type name="Magento\Framework\GraphQl\Query\Resolver\Argument\Validator\SearchCriteriaValidator">
<arguments>
- <argument name="maxPageSize" xsi:type="number">300</argument>
+ <argument name="maxPageSize" xsi:type="number">999999</argument>
</arguments>
</type>
<type name="Magento\Framework\Webapi\ServiceInputProcessor">
diff --git a/app/etc/di.xml b/app/etc/di.xml
index 078fe71913f..6ab3bdfd35c 100644
--- a/app/etc/di.xml
+++ b/app/etc/di.xml
@@ -1946,12 +1946,12 @@
</type>
<type name="Magento\Framework\Webapi\Validator\EntityArrayValidator">
<arguments>
- <argument name="complexArrayItemLimit" xsi:type="number">20</argument>
+ <argument name="complexArrayItemLimit" xsi:type="number">999999</argument>
</arguments>
</type>
<type name="Magento\Framework\Webapi\Validator\SearchCriteriaValidator">
<arguments>
- <argument name="maximumPageSize" xsi:type="number">300</argument>
+ <argument name="maximumPageSize" xsi:type="number">999999</argument>
</arguments>
</type>
<preference for="Magento\Framework\GraphQl\Query\Resolver\Argument\ValidatorInterface" type="Magento\Framework\GraphQl\Query\Resolver\Argument\Validator\CompositeValidator"/>
@@ -1964,7 +1964,7 @@
</type>
<type name="Magento\Framework\GraphQl\Query\Resolver\Argument\Validator\SearchCriteriaValidator">
<arguments>
- <argument name="maxPageSize" xsi:type="number">300</argument>
+ <argument name="maxPageSize" xsi:type="number">999999</argument>
</arguments>
</type>
<type name="Magento\Framework\Webapi\ServiceInputProcessor">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment