Skip to content

Commit d1f3597

Browse files
Autofix
1 parent d71e123 commit d1f3597

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ interface ValidationCache
1818
*/
1919
public function isValidated(Schema $schema, DocumentNode $ast): bool;
2020

21-
/**
22-
* Cache validation status for this schema/query.
23-
*/
21+
/** Cache validation status for this schema/query. */
2422
public function markValidated(Schema $schema, DocumentNode $ast): void;
25-
}
23+
}

tests/Executor/ValidationWithCacheTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,23 @@
2020
final class SpyValidationCacheAdapter extends PsrValidationCacheAdapter
2121
{
2222
public int $isValidatedCalls = 0;
23+
2324
public int $markValidatedCalls = 0;
2425

2526
public function isValidated(Schema $schema, DocumentNode $ast): bool
2627
{
27-
$this->isValidatedCalls++;
28+
++$this->isValidatedCalls;
29+
2830
return parent::isValidated($schema, $ast);
2931
}
3032

3133
public function markValidated(Schema $schema, DocumentNode $ast): void
3234
{
33-
$this->markValidatedCalls++;
35+
++$this->markValidatedCalls;
3436
parent::markValidated($schema, $ast);
3537
}
3638
}
3739

38-
3940
final class ValidationWithCacheTest extends TestCase
4041
{
4142
use ArraySubsetAsserts;
@@ -99,8 +100,8 @@ public function testIsValidationCachedWithAdapter(): void
99100
}';
100101

101102
// make the same call twice in a row. We'll then inspect the cache object to count calls
102-
GraphQL::executeQuery( $schema, $query, null, null, null, null, null, null, $cache)->toArray();
103-
$result = GraphQL::executeQuery( $schema, $query, null, null, null, null, null, null, $cache)->toArray();
103+
GraphQL::executeQuery($schema, $query, null, null, null, null, null, null, $cache)->toArray();
104+
$result = GraphQL::executeQuery($schema, $query, null, null, null, null, null, null, $cache)->toArray();
104105

105106
// ✅ Assert that validation only happened once
106107
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-next-line */
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)