You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use ValidationCache interface from webonyx/graphql-php
Implement the ValidationCache interface from webonyx/graphql-php#1730
to improve validation result caching with automatic cache invalidation.
Cache key now includes:
- Library versions (webonyx/graphql-php and nuwave/lighthouse)
- Schema hash
- Query hash
- Rule configuration hash (max_query_depth, disable_introspection)
This eliminates the need for manual cache clearing when upgrading
graphql-php or lighthouse, as the cache auto-invalidates on version
changes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Other reasons to clear the query cache completely include:
55
55
56
-
- you plan to upgrade the package `webonyx/graphql-php` to a new version that changes the internal representation of parsed queries
57
56
- you have stale queries in your cache that have an inappropriate or missing TTL
58
57
- you want to free up disk space used by cached query files
59
58
@@ -68,11 +67,23 @@ APQ is enabled by default, but depends on query caching being enabled.
68
67
69
68
Lighthouse can cache the result of the query validation process as well.
70
69
It only caches queries without errors.
71
-
`QueryComplexity` validation can not be cached as it is dependent on the query, so it is always executed.
70
+
`QueryComplexity` validation can not be cached as it depends on runtime variables, so it is always executed.
72
71
73
72
Query validation caching is disabled by default.
74
73
You can enable it by setting `validation_cache.enable` to `true` in `config/lighthouse.php`.
75
74
75
+
### Cache key components
76
+
77
+
The validation cache key includes:
78
+
79
+
- Library versions (`webonyx/graphql-php` and `nuwave/lighthouse`) - cache is automatically invalidated when upgrading
80
+
- Schema hash - cache is invalidated when the schema changes
81
+
- Query hash - each unique query has its own cache entry
82
+
- Rule configuration hash (`max_query_depth`, `disable_introspection`) - cache is invalidated when security settings change
83
+
84
+
This ensures that cached validation results are automatically invalidated when any of the inputs that affect validation change.
85
+
You do not need to manually clear the cache when upgrading these libraries.
86
+
76
87
## Testing caveats
77
88
78
89
If you are mocking Laravel cache classes like `Illuminate\Support\Facades\Cache` or `Illuminate\Cache\Repository` and asserting expectations in your unit tests, it might be best to disable the query cache in your `phpunit.xml`:
@@ -396,36 +397,26 @@ protected function validateCacheableRules(
396
397
}
397
398
398
399
if ($queryHash === null) {
399
-
return DocumentValidator::validate($schema, $query, $validationRules);// @phpstan-ignore return.type (TODO remove ignore when requiring a newer version of webonyx/graphql-php)
return DocumentValidator::validate($schema, $query, $validationRules);// @phpstan-ignore return.type (TODO remove ignore when requiring a newer version of webonyx/graphql-php)
0 commit comments