Skip to content

Commit a745345

Browse files
Autofix
1 parent 51d1087 commit a745345

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

docs/class-reference.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ static function executeQuery(
7070
?array $variableValues = null,
7171
?string $operationName = null,
7272
?callable $fieldResolver = null,
73-
?array $validationRules = null
73+
?array $validationRules = null,
74+
?GraphQL\Validator\ValidationCache $cache = null
7475
): GraphQL\Executor\ExecutionResult
7576
```
7677

@@ -98,7 +99,8 @@ static function promiseToExecute(
9899
?array $variableValues = null,
99100
?string $operationName = null,
100101
?callable $fieldResolver = null,
101-
?array $validationRules = null
102+
?array $validationRules = null,
103+
?GraphQL\Validator\ValidationCache $cache = null
102104
): GraphQL\Executor\Promise\Promise
103105
```
104106

@@ -1811,7 +1813,8 @@ static function validate(
18111813
GraphQL\Type\Schema $schema,
18121814
GraphQL\Language\AST\DocumentNode $ast,
18131815
?array $rules = null,
1814-
?GraphQL\Utils\TypeInfo $typeInfo = null
1816+
?GraphQL\Utils\TypeInfo $typeInfo = null,
1817+
?GraphQL\Validator\ValidationCache $cache = null
18151818
): array
18161819
```
18171820

src/Validator/ValidationCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface ValidationCache
2626
* for example, when using persisted queries that are known to be valid ahead of time. In such cases, you
2727
* can implement this method to always return true.
2828
*
29-
* @return bool True if validation for the given schema + AST is already known to be valid; false otherwise.
29+
* @return bool true if validation for the given schema + AST is already known to be valid; false otherwise
3030
*/
3131
public function isValidated(Schema $schema, DocumentNode $ast): bool;
3232

@@ -37,4 +37,4 @@ public function isValidated(Schema $schema, DocumentNode $ast): bool;
3737
* You should store enough information to recognize this combination on future requests.
3838
*/
3939
public function markValidated(Schema $schema, DocumentNode $ast): void;
40-
}
40+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?php
2-
1+
<?php declare(strict_types=1);
32

43
namespace GraphQL\Tests\Executor\TestClasses;
54

@@ -10,19 +9,20 @@
109
final class SpyValidationCacheAdapter extends PsrValidationCacheAdapter
1110
{
1211
public int $isValidatedCalls = 0;
12+
1313
public int $markValidatedCalls = 0;
1414

1515
public function isValidated(Schema $schema, DocumentNode $ast): bool
1616
{
17-
$this->isValidatedCalls++;
17+
++$this->isValidatedCalls;
1818

1919
return parent::isValidated($schema, $ast);
2020
}
2121

2222
public function markValidated(Schema $schema, DocumentNode $ast): void
2323
{
24-
$this->markValidatedCalls++;
24+
++$this->markValidatedCalls;
2525

2626
parent::markValidated($schema, $ast);
2727
}
28-
}
28+
}

tests/Executor/ValidationWithCacheTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ public function testIsValidationCachedWithAdapter(): void
7979
}';
8080

8181
// make the same call twice in a row. We'll then inspect the cache object to count calls
82-
$resultA = GraphQL::executeQuery( $schema, $query, null, null, null, null, null, null, $cache)->toArray();
83-
$resultB = GraphQL::executeQuery( $schema, $query, null, null, null, null, null, null, $cache)->toArray();
84-
82+
$resultA = GraphQL::executeQuery($schema, $query, null, null, null, null, null, null, $cache)->toArray();
83+
$resultB = GraphQL::executeQuery($schema, $query, null, null, null, null, null, null, $cache)->toArray();
8584

8685
// ✅ Assert that validation only happened once
8786
self::assertEquals(2, $cache->isValidatedCalls, 'Should check cache twice');

tests/PsrValidationCacheAdapter.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,33 @@
1212
class PsrValidationCacheAdapter implements ValidationCache
1313
{
1414
private const KEY_PREFIX = 'gql_validation_';
15+
1516
private int $ttl;
17+
1618
private CacheInterface $cache;
1719

1820
public function __construct(
19-
CacheInterface $cache,
21+
CacheInterface $cache,
2022
int $ttlSeconds = 300
2123
) {
2224
$this->ttl = $ttlSeconds;
2325
$this->cache = $cache;
2426
}
2527

26-
/**
27-
* @throws InvalidArgumentException
28-
*/
28+
/** @throws InvalidArgumentException */
2929
public function isValidated(Schema $schema, DocumentNode $ast): bool
3030
{
3131
try {
3232
$key = $this->buildKey($schema, $ast);
33+
3334
/** @phpstan-ignore missingType.checkedException */
3435
return $this->cache->has($key);
3536
} catch (\Throwable $e) {
3637
return false;
3738
}
3839
}
3940

40-
/**
41-
* @throws InvalidArgumentException
42-
*/
41+
/** @throws InvalidArgumentException */
4342
public function markValidated(Schema $schema, DocumentNode $ast): void
4443
{
4544
try {

0 commit comments

Comments
 (0)