yireo/magento2-graph-ql-rate-limiting
Composer 安装命令:
composer require yireo/magento2-graph-ql-rate-limiting
包简介
Magento 2 module to add rate limiting to GraphQL resources
README 文档
README
Magento 2 module to add rate limiting to GraphQL resources
WARNING: As of yet, the sunspikes/php-ratelimiter library is no longer being maintained. And because of this, this module is dead, until it is refactored to use another rate limiting tool.
This module implements the sunspikes/php-ratelimiter in Magento 2. It checks how many GraphQL mutations and/or GraphQL queries are sent from a specific client to a Magento instance and if the number of these requests exceeds a configured maximum, a GraphQL error is generated.
This module is specifically recommended for limiting mutations, so that your Magento shop is not flooded with fake requests to create sessions, customers or other data. Usually, in a headless environment, the amount of mutations is limited.
Usage
Install this extension:
composer require yireo/magento2-graph-ql-rate-limiting
bin/magento module:enable Yireo_GraphQlRateLimiting
bin/magento setup:upgrade
Next, login to the Magento Admin Panel, navigate to Store Configuration and then Yireo > Yireo GraphQlRateLimiting > Settings and modify the settings to your needs. The default might be fine though. The settings Enabled and Limit Mutations are definitely to be enabled, otherwise this extension is kind of pointless. Whether Limit Queries is useful up to you. The settings Maximum Queries and Maximum Mutations refer to the maximum amount of queries or mutations to be made within a certain timeframe (Timeframe) before a connection is denied for the remainder of that timeframe.
Finally, navigate to Cache Management and enable the cache GraphQL Rate Limiting:
bin/magento cache:enable graphql_rate_limiting
Testing to see if this works
Open up GraphiQL or some other client and create a simple request like the following:
query { products(filter: {name: {match: "jacket"}}) { items { sku } } }
Configure the following settings in this Magento module (under the Store Configuration):
- Enabled: Yes
- Limit Queries: Yes
- Maximum Queries: 3
After running the same query three-times an error should popup up:
{
"errors": [
{
"message": "A maximum of 3 queries has been reached.",
"extensions": {
"category": "graphql"
}
}
]
}
Testing of the cache type
This extension adds a Cache Type GRAPHQL_RATE_LIMITING to the Magento cache frontends. To test whether the Cache Type is working, you can run the following Functional Test:
bin/magento cache:status bin/magento cache:enable graphql_rate_limiting vendor/bin/phpunit --bootstrap=app/bootstrap.php app/code/Yireo/GraphQlRateLimiting/Test/Functional/CacheTypeTest.php
Other functional tests
To run other functional tests, the following can be used:
bin/magento cache:enable graphql_rate_limiting vendor/bin/phpunit --bootstrap=app/bootstrap.php app/code/Yireo/GraphQlRateLimiting/Test/Functional/
Please note that this resets your configuration. Do not do this on a live Magento site.
Todo
- Make compatible with PHP 8
- Allow saving data in Redis
- Check what Adobe Commerce uses for
backpressure-logger - Add integation tests
- Add
MovingWindowSettingsandFixedWindowSettings - Allow for specific endpoints to be limited
- Make sure to reply with HTTP/1.1 429 Too Many Requests
yireo/magento2-graph-ql-rate-limiting 适用场景与选型建议
yireo/magento2-graph-ql-rate-limiting 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.47k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2020 年 04 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「magento」 「composer-installer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yireo/magento2-graph-ql-rate-limiting 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yireo/magento2-graph-ql-rate-limiting 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yireo/magento2-graph-ql-rate-limiting 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Entity services for magento2
Module to add React to Magento 2 KO frontend
Composer installer for Magento modules
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
Magento - Clean up session extension
统计信息
- 总下载量: 21.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: OSL-3.0
- 更新时间: 2020-04-18