33namespace GraphQL \Validator ;
44
55use GraphQL \Language \AST \DocumentNode ;
6+ use GraphQL \Tests \PsrValidationCacheAdapter ;
67use GraphQL \Type \Schema ;
78
89/**
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.
1116 */
1217interface ValidationCache
1318{
1419 /**
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.
1830 */
1931 public function isValidated (Schema $ schema , DocumentNode $ ast ): bool ;
2032
2133 /**
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.
2338 */
2439 public function markValidated (Schema $ schema , DocumentNode $ ast ): void ;
2540}
0 commit comments