Skip to content

Commit

Permalink
Use default laravel throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner committed Mar 28, 2024
1 parent a9a07b7 commit 77fbf30
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 45 deletions.
2 changes: 1 addition & 1 deletion config/enjin-platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,6 @@
'rate_limit' => [
'enabled' => env('RATE_LIMIT_ENABLED', true),
'attempts' => env('RATE_LIMIT_ATTEMPTS', 500),
'time' => env('RATE_LIMIT_TIME', 60),
'time' => env('RATE_LIMIT_TIME', 1), // minutes
],
];
1 change: 0 additions & 1 deletion config/graphql.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// This middleware will apply to all schemas
'middleware' => [
Illuminate\Session\Middleware\StartSession::class,
Enjin\Platform\Middlewares\RateLimit::class,
Enjin\Platform\Middlewares\Authenticated::class,
],

Expand Down
1 change: 0 additions & 1 deletion lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@
'unable_to_process' => "Sorry, we're unable to process your request at this time. Please try again later.",
'no_collection' => 'Unable to find a collection for token ID :tokenId.',
'cannot_retry_transaction' => 'Cannot retry FINALIZED transaction.',
'too_many_requests' => 'Too many requests. Retry in :num seconds',
];
9 changes: 9 additions & 0 deletions src/Http/Controllers/GraphQLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@

class GraphQLController extends GraphQLGraphQLController
{
public function __construct()
{
if (config('enjin-platform.rate_limit.enabled')) {
$this->middleware(
'throttle:' . config('enjin-platform.rate_limit.attempts') . ',' . config('enjin-platform.rate_limit.time')
);
}
}

/**
* Handle graphql query.
*/
Expand Down
41 changes: 0 additions & 41 deletions src/Middlewares/RateLimit.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Feature/GraphQL/Middleware/RateLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function test_it_can_rate_limit(): void
['query' => static::$queries['GetCollections']],
);
$result = $response->getData(true);
$this->assertStringContainsString('Too many requests.', Arr::get($result, 'message'));
$this->assertStringContainsString('Too Many Attempts.', Arr::get($result, 'message'));
}

public function test_it_will_not_rate_limit(): void
Expand Down

0 comments on commit 77fbf30

Please sign in to comment.