3
3
namespace GraphQL \Validator ;
4
4
5
5
use GraphQL \Language \AST \DocumentNode ;
6
+ use GraphQL \Tests \PsrValidationCacheAdapter ;
6
7
use GraphQL \Type \Schema ;
7
8
8
9
/**
9
- * Implement this interface and pass an instance to GraphQL::executeQuery to cache validation of ASTs.
10
- * The details of how to compute any keys (or whether to validate at all) are left up to you.
10
+ * Implement this interface and pass an instance to GraphQL::executeQuery to enable caching of successful query validations.
11
+ *
12
+ * This can improve performance by skipping validation for known-good query and schema combinations.
13
+ * You are responsible for defining how cache keys are computed, and when validation should be skipped.
14
+ *
15
+ * @see PsrValidationCacheAdapter for a toy implementation.
11
16
*/
12
17
interface ValidationCache
13
18
{
14
19
/**
15
- * Return true if the given schema + AST pair has previously been validated successfully.
16
- * Only successful validations are cached.
17
- * A return value of false means the pair is either unknown or has not been validated yet.
20
+ * Determine whether the given schema + AST pair has already been successfully validated.
21
+ *
22
+ * This method should return true if the query has previously passed validation for the provided schema.
23
+ * Only successful validations should be considered "cached" — failed validations are not cached.
24
+ *
25
+ * Note: This allows for optimizations in systems where validation may not be necessary on every request —
26
+ * for example, when using persisted queries that are known to be valid ahead of time. In such cases, you
27
+ * can implement this method to always return true.
28
+ *
29
+ * @return bool True if validation for the given schema + AST is already known to be valid; false otherwise.
18
30
*/
19
31
public function isValidated (Schema $ schema , DocumentNode $ ast ): bool ;
20
32
21
33
/**
22
- * Cache validation status for this schema/query.
34
+ * Mark the given schema + AST pair as successfully validated.
35
+ *
36
+ * This is typically called after a query passes validation.
37
+ * You should store enough information to recognize this combination on future requests.
23
38
*/
24
39
public function markValidated (Schema $ schema , DocumentNode $ ast ): void ;
25
40
}
0 commit comments