-
-
Notifications
You must be signed in to change notification settings - Fork 572
Expand file tree
/
Copy pathValidationCache.php
More file actions
46 lines (42 loc) · 2.06 KB
/
ValidationCache.php
File metadata and controls
46 lines (42 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php declare(strict_types=1);
namespace GraphQL\Validator;
use GraphQL\Language\AST\DocumentNode;
use GraphQL\Type\Schema;
use GraphQL\Validator\Rules\ValidationRule;
/**
* Implement this interface and pass an instance to GraphQL::executeQuery to enable caching of successful query validations.
*
* This can improve performance by skipping validation for known-good combinations of query, schema, and rules.
* You are responsible for defining how cache keys are computed.
*
* Some things to keep in mind when generating keys:
* - PHP's `serialize()` function is fast, but can't handle certain structures such as closures.
* - If your `$schema` includes closures or is too large or complex to serialize,
* consider using a build-time version number or environment-based fingerprint instead.
* - Keep in mind that there are internal `$rules` that are applied in addition to any you pass in,
* and it's possible these may shift or expand as the library evolves,
* so it might make sense to include the library version number in your keys.
*/
interface ValidationCache
{
/**
* Determine whether the given schema/AST/rules set has already been successfully validated.
*
* This method should return true if the query has previously passed validation for the provided schema.
* Only successful validations should be considered "cached" — failed validations are not cached.
*
* @param array<ValidationRule>|null $rules
*
* @return bool true if validation for the given schema + AST + rules is already known to be valid; false otherwise
*/
public function isValidated(Schema $schema, DocumentNode $ast, ?array $rules = null): bool;
/**
* @param array<ValidationRule>|null $rules
*
* Mark the given schema/AST/rules set as successfully validated.
*
* This is typically called after a query passes validation.
* You should store enough information to recognize this combination on future requests.
*/
public function markValidated(Schema $schema, DocumentNode $ast, ?array $rules = null): void;
}