-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
650 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Benchmarks; | ||
|
||
final class HugeRequestBench extends QueryBench | ||
{ | ||
protected string $schema = /** @lang GraphQL */ <<<'GRAPHQL' | ||
type Query { | ||
foo: String! | ||
@field(resolver: "Benchmarks\\HugeRequestBench@resolve") | ||
} | ||
GRAPHQL; | ||
|
||
protected ?string $query = null; | ||
|
||
/** | ||
* Resolves foo. | ||
* | ||
* @skip | ||
*/ | ||
public function resolve(): string | ||
{ | ||
return 'foo'; | ||
} | ||
|
||
/** Generates query with $count fragments. */ | ||
private function generateQuery(int $count): string | ||
{ | ||
$query = '{'; | ||
for ($i = 0; $i < $count; ++$i) { | ||
$query .= '...foo' . $i . PHP_EOL; | ||
} | ||
|
||
$query .= '}' . PHP_EOL; | ||
for ($i = 0; $i < $count; ++$i) { | ||
$query .= 'fragment foo' . $i . ' on Query {' . PHP_EOL; | ||
$query .= 'foo' . PHP_EOL; | ||
$query .= '}' . PHP_EOL; | ||
} | ||
|
||
return $query; | ||
} | ||
|
||
/** | ||
* @Warmup(1) | ||
* | ||
* @Revs(10) | ||
* | ||
* @Iterations(10) | ||
* | ||
* @ParamProviders({"providePerformanceTuning"}) | ||
* | ||
* @BeforeMethods("setPerformanceTuning") | ||
*/ | ||
public function benchmark1(): void | ||
{ | ||
$this->query ??= $this->generateQuery(1); | ||
$this->graphQL($this->query); | ||
} | ||
|
||
/** | ||
* @Warmup(1) | ||
* | ||
* @Revs(10) | ||
* | ||
* @Iterations(10) | ||
* | ||
* @ParamProviders({"providePerformanceTuning"}) | ||
* | ||
* @BeforeMethods("setPerformanceTuning") | ||
*/ | ||
public function benchmark10(): void | ||
{ | ||
$this->query ??= $this->generateQuery(10); | ||
$this->graphQL($this->query); | ||
} | ||
|
||
/** | ||
* @Warmup(1) | ||
* | ||
* @Revs(10) | ||
* | ||
* @Iterations(10) | ||
* | ||
* @ParamProviders({"providePerformanceTuning"}) | ||
* | ||
* @BeforeMethods("setPerformanceTuning") | ||
*/ | ||
public function benchmark100(): void | ||
{ | ||
$this->query ??= $this->generateQuery(100); | ||
$this->graphQL($this->query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Nuwave\Lighthouse\Execution; | ||
|
||
use GraphQL\Validator\DocumentValidator; | ||
use GraphQL\Validator\Rules\DisableIntrospection; | ||
use GraphQL\Validator\Rules\QueryComplexity; | ||
use GraphQL\Validator\Rules\QueryDepth; | ||
use Illuminate\Contracts\Config\Repository as ConfigRepository; | ||
use Nuwave\Lighthouse\Support\Contracts\ProvidesCacheableValidationRules; | ||
|
||
class CacheableValidationRulesProvider implements ProvidesCacheableValidationRules | ||
{ | ||
public function __construct( | ||
protected ConfigRepository $configRepository, | ||
) {} | ||
|
||
public function cacheableValidationRules(): array | ||
{ | ||
$result = [ | ||
QueryDepth::class => new QueryDepth($this->configRepository->get('lighthouse.security.max_query_depth', 0)), | ||
DisableIntrospection::class => new DisableIntrospection($this->configRepository->get('lighthouse.security.disable_introspection', 0)), | ||
] + DocumentValidator::allRules(); | ||
|
||
unset($result[QueryComplexity::class]); | ||
|
||
return $result; | ||
} | ||
|
||
public function validationRules(): ?array | ||
{ | ||
$maxQueryComplexity = $this->configRepository->get('lighthouse.security.max_query_complexity', 0); | ||
|
||
return $maxQueryComplexity === 0 | ||
? [] | ||
: [ | ||
QueryComplexity::class => new QueryComplexity($maxQueryComplexity), | ||
]; | ||
} | ||
} |
Oops, something went wrong.