Skip to content
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

Init Graphql base #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions EventListener/RateLimitListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,24 @@ public function onKernelRequest(RequestEvent $event)
}

// only process on master request
if (!$event->isMasterRequest()) {
if (method_exists($event, 'isMasterRequest') && !$event->isMasterRequest()) {
return;
}

if (!$event->isMainRequest()) {
return;
}

$request = $event->getRequest();
if (!$request->attributes->has('_api_resource_class')) {
if (!$request->attributes->has('_api_resource_class') && !$request->attributes->has('_graphql')) {
return;
}

$this->rateLimitHandler->handle($request);
if ($request->attributes->has('_api_resource_class')) {
$this->rateLimitHandler->handle($request);
} else {
$this->rateLimitHandler->handleGraphQL($request);
}

if ($this->rateLimitHandler->isEnabled()) {
$request->attributes->set('_api_rate_limit_info', $this->rateLimitHandler->getRateLimitInfo());
Expand Down
11 changes: 11 additions & 0 deletions Service/RateLimitHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ public function handle(Request $request)
}
}

public function handleGraphQL(Request $request)
{
$annotation = new ApiRateLimit();

list($key, $limit, $period) = $this->getThrottle($request, $annotation);

if ($this->enabled) {
$this->decreaseRateLimitRemaining($key, $limit, $period);
}
}

/**
* @throws \Psr\Cache\InvalidArgumentException
*/
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"php": "^7.1.3 || ^8.0",
"api-platform/core": "^2.4",
"doctrine/annotations": "^1.4",
"symfony/cache": "^3.4 || ^4.4 || ^5.0",
"symfony/config": "^3.4 || ^4.4 || ^5.0",
"symfony/dependency-injection": "^3.4 || ^4.4 || ^5.0",
"symfony/http-foundation": "^3.4 || ^4.4 || ^5.0",
"symfony/http-kernel": "^4.4 || ^5.0",
"symfony/security-bundle": "^3.4 || ^4.4 || ^5.0"
"symfony/cache": "^3.4 || ^4.4 || ^5.0 || ^6.0",
"symfony/config": "^3.4 || ^4.4 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^3.4 || ^4.4 || ^5.0 || ^6.0",
"symfony/http-foundation": "^3.4 || ^4.4 || ^5.0 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
"symfony/security-bundle": "^3.4 || ^4.4 || ^5.0 || ^6.0"
},
"autoload": {
"psr-4": {
Expand Down