8
8
use GraphQL \Language \AST \DocumentNode ;
9
9
use GraphQL \Type \Schema ;
10
10
use GraphQL \Utils \SchemaPrinter ;
11
+ use GraphQL \Validator \Rules \ValidationRule ;
11
12
use GraphQL \Validator \ValidationCache ;
12
13
use Psr \SimpleCache \CacheInterface ;
13
14
use Psr \SimpleCache \InvalidArgumentException ;
@@ -27,40 +28,46 @@ public function __construct(
27
28
}
28
29
29
30
/**
31
+ * @param array<ValidationRule>|null $rules
32
+ *
30
33
* @throws \JsonException
31
34
* @throws Error
32
35
* @throws InvalidArgumentException&\Throwable
33
36
* @throws InvariantViolation
34
37
* @throws SerializationError
35
38
*/
36
- public function isValidated (Schema $ schema , DocumentNode $ ast ): bool
39
+ public function isValidated (Schema $ schema , DocumentNode $ ast, array $ rules = null ): bool
37
40
{
38
41
$ key = $ this ->buildKey ($ schema , $ ast );
39
42
40
43
return $ this ->cache ->has ($ key ); // @phpstan-ignore missingType.checkedException (annotated as a union with Throwable)
41
44
}
42
45
43
46
/**
47
+ * @param array<ValidationRule>|null $rules
48
+ *
44
49
* @throws \JsonException
45
50
* @throws Error
46
51
* @throws InvalidArgumentException&\Throwable
47
52
* @throws InvariantViolation
48
53
* @throws SerializationError
49
54
*/
50
- public function markValidated (Schema $ schema , DocumentNode $ ast ): void
55
+ public function markValidated (Schema $ schema , DocumentNode $ ast, array $ rules = null ): void
51
56
{
52
57
$ key = $ this ->buildKey ($ schema , $ ast );
53
58
54
59
$ this ->cache ->set ($ key , true , $ this ->ttlSeconds ); // @phpstan-ignore missingType.checkedException (annotated as a union with Throwable)
55
60
}
56
61
57
62
/**
63
+ * @param array<ValidationRule>|null $rules
64
+ *
58
65
* @throws \JsonException
59
66
* @throws Error
60
67
* @throws InvariantViolation
61
68
* @throws SerializationError
62
69
*/
63
- private function buildKey (Schema $ schema , DocumentNode $ ast ): string
70
+ private function buildKey (Schema $ schema , DocumentNode $ ast, array $ rules = null ): string
64
71
{
65
72
/**
66
73
* This default strategy generates a cache key by hashing the printed schema and AST.
@@ -69,7 +76,8 @@ private function buildKey(Schema $schema, DocumentNode $ast): string
69
76
*/
70
77
$ schemaHash = md5 (SchemaPrinter::doPrint ($ schema ));
71
78
$ astHash = md5 (serialize ($ ast ));
79
+ $ rulesHash = md5 (serialize ($ rules ));
72
80
73
- return "graphql_validation_ {$ schemaHash }_ {$ astHash }" ;
81
+ return "graphql_validation_ {$ schemaHash }_ {$ astHash }_ $ rulesHash " ;
74
82
}
75
83
}
0 commit comments