4949use GraphQL \Validator \Rules \ValuesOfCorrectType ;
5050use GraphQL \Validator \Rules \VariablesAreInputTypes ;
5151use GraphQL \Validator \Rules \VariablesInAllowedPosition ;
52- use Psr \SimpleCache \CacheInterface ;
53- use Psr \SimpleCache \InvalidArgumentException ;
5452
5553/**
5654 * Implements the "Validation" section of the spec.
@@ -102,18 +100,13 @@ public static function validate(
102100 DocumentNode $ ast ,
103101 ?array $ rules = null ,
104102 ?TypeInfo $ typeInfo = null ,
105- ?CacheInterface $ cache = null
103+ ?ValidationCache $ cache = null
106104 ): array {
107- $ cacheKey = null ;
108-
109105 if (isset ($ cache )) {
110- $ cacheKey = 'gql_validation_ ' . md5 ($ ast ->__toString ());
111-
112- try {
113- if ($ cache ->has ($ cacheKey )) {
114- return $ cache ->get ($ cacheKey );
115- }
116- } catch (InvalidArgumentException $ e ) {}
106+ $ cached = $ cache ->isValidated ($ schema , $ ast );
107+ if ($ cached ) {
108+ return [];
109+ }
117110 }
118111
119112 $ rules ??= static ::allRules ();
@@ -140,11 +133,9 @@ public static function validate(
140133 $ errors = $ context ->getErrors ();
141134
142135 // Only cache clean results
143- try {
144- if (isset ($ cacheKey ) && count ($ errors ) === 0 ) {
145- $ cache ->set ($ cacheKey , $ errors );
146- }
147- } catch (InvalidArgumentException $ e ) {}
136+ if (isset ($ cache ) && count ($ errors ) === 0 ) {
137+ $ cache ->markValidated ($ schema , $ ast );
138+ }
148139
149140 return $ errors ;
150141 }
0 commit comments