infinityloop-dev / graphpinator-persisted-queries
Module to persist validated query in cache and improve performace of repeating queries.
Installs: 10 985
Dependents: 3
Suggesters: 1
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 4
Requires
- php: >=8.1
- infinityloop-dev/graphpinator: ^1.6
- infinityloop-dev/utils: ^2.3
- psr/simple-cache: ^3.0.0
Requires (Dev)
- infection/infection: ^0.27
- infinityloop-dev/coding-standard: ^0.2
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.4
This package is auto-updated.
Last update: 2024-11-06 17:11:46 UTC
README
⚡🌐⚡ Module to persist validated query in cache and improve performace of repeating queries.
Introduction
This Module allows GraPHPinator to cache queries on the server to reduce server load. This module aims to reduce GraphQL overhead in parsing and validation by caching and reusing known requests.
Please note that this module does not affect the speed of your resolver functions.
Installation
Install package using composer
composer require infinityloop-dev/graphpinator-persisted-queries
How to use
- Implement
\Psr\SimpleCache\CacheInterface
You need implementation of \Psr\SimpleCache\CacheInterface
where the serialized version of request is stored for later reuse.
- Register
PersistedQueriesModule
as GraPHPinator module:
$persistModule = new \Graphpinator\PersistedQueriesModule\PersistedQueriesModule($schema, $cacheImpl); $graphpinator = new \Graphpinator\Graphpinator( $schema, $catchExceptions, new \Graphpinator\Module\ModuleSet([$persistModule, /* possibly other modules */]), $logger, );
- You are all set, queries are automatically cached in specified storage.
Performance improvements
Simple benchmark (code in bench
directory) shows approximatelly 80% reduction of GraphQL overhead.
Benchmark runs the same query 10k times, with 5 warmup queries before. Cache in use is a simple implementation using Redis on localhost, connection is done using php-redis extension. Opcache was disabled.