88use GraphQL \Language \AST \DocumentNode ;
99use GraphQL \Type \Schema ;
1010use GraphQL \Utils \SchemaPrinter ;
11+ use GraphQL \Validator \Rules \ValidationRule ;
1112use GraphQL \Validator \ValidationCache ;
1213use Psr \SimpleCache \CacheInterface ;
1314use Psr \SimpleCache \InvalidArgumentException ;
@@ -27,40 +28,46 @@ public function __construct(
2728 }
2829
2930 /**
31+ * @param array<ValidationRule>|null $rules
32+ *
3033 * @throws \JsonException
3134 * @throws Error
3235 * @throws InvalidArgumentException&\Throwable
3336 * @throws InvariantViolation
3437 * @throws SerializationError
3538 */
36- public function isValidated (Schema $ schema , DocumentNode $ ast ): bool
39+ public function isValidated (Schema $ schema , DocumentNode $ ast, array $ rules = null ): bool
3740 {
3841 $ key = $ this ->buildKey ($ schema , $ ast );
3942
4043 return $ this ->cache ->has ($ key ); // @phpstan-ignore missingType.checkedException (annotated as a union with Throwable)
4144 }
4245
4346 /**
47+ * @param array<ValidationRule>|null $rules
48+ *
4449 * @throws \JsonException
4550 * @throws Error
4651 * @throws InvalidArgumentException&\Throwable
4752 * @throws InvariantViolation
4853 * @throws SerializationError
4954 */
50- public function markValidated (Schema $ schema , DocumentNode $ ast ): void
55+ public function markValidated (Schema $ schema , DocumentNode $ ast, array $ rules = null ): void
5156 {
5257 $ key = $ this ->buildKey ($ schema , $ ast );
5358
5459 $ this ->cache ->set ($ key , true , $ this ->ttlSeconds ); // @phpstan-ignore missingType.checkedException (annotated as a union with Throwable)
5560 }
5661
5762 /**
63+ * @param array<ValidationRule>|null $rules
64+ *
5865 * @throws \JsonException
5966 * @throws Error
6067 * @throws InvariantViolation
6168 * @throws SerializationError
6269 */
63- private function buildKey (Schema $ schema , DocumentNode $ ast ): string
70+ private function buildKey (Schema $ schema , DocumentNode $ ast, array $ rules = null ): string
6471 {
6572 /**
6673 * 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
6976 */
7077 $ schemaHash = md5 (SchemaPrinter::doPrint ($ schema ));
7178 $ astHash = md5 (serialize ($ ast ));
79+ $ rulesHash = md5 (serialize ($ rules ));
7280
73- return "graphql_validation_ {$ schemaHash }_ {$ astHash }" ;
81+ return "graphql_validation_ {$ schemaHash }_ {$ astHash }_ $ rulesHash " ;
7482 }
7583}
0 commit comments