sisl-source / magento2-automatic-persisted-queries
Apollo-compatible automatic persisted queries, to improve GraphQL network performance.
Package info
github.com/SISL-source/magento2-automatic-persisted-queries
Type:magento2-module
pkg:composer/sisl-source/magento2-automatic-persisted-queries
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
- magento/framework: >=103.0.4 <104
- magento/module-graph-ql: >=100.4.0 <101
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
An Apollo-compatible Automatic Persisted Queries implementation for GraphQL in Magento 2. Instead of sending the whole GraphQL query over and over, the client sends only its SHA-256 hash; the full query goes to the server once and is remembered. The result:
- smaller GraphQL request payloads (the frontend sends a hash instead of kilobytes of query),
- queries over GET instead of POST → cacheable on a CDN / at the edge,
- less network overhead for headless / PWA frontends (Apollo Client,
apollo-link-persisted-queries).
This is a maintained fork of the abandoned danslo/magento2-module-automatic-persisted-queries
(last upstream commit: 2023). The original declares no require in composer.json (it mounts
anywhere, untested against newer releases) and ships no etc/acl.xml, even though system.xml
references the Danslo_Apq::config_apq resource — which left the admin configuration section
effectively inaccessible. This fork fixes that and is verified on 2.4.9 / PHP 8.4.
What the fork fixes
- Added
etc/acl.xmlwith theDanslo_Apq::config_apqresource (underMagento_Config::config) — the Stores → Configuration → General → Automatic Persisted Queries section is now visible and saveable. (a real bug in the original) - Filled in
composer.json:php: ~8.1.0 || … || ~8.5.0,magento/framework: >=103.0.4 <104,magento/module-graph-ql: >=100.4.0 <101(instead of no requirements at all). - Magento 2.4.9 compatibility confirmed with a real test of the full APQ handshake (see below).
Compatibility
- Magento 2.4.4 – 2.4.9 (Open Source / Adobe Commerce)
- PHP 8.1 – 8.4
Installation
composer require sisl-source/magento2-automatic-persisted-queries bin/magento module:enable Danslo_Apq bin/magento cache:enable apq # cache type for the persisted queries bin/magento setup:upgrade bin/magento setup:di:compile # production mode
How the handshake works (Apollo APQ)
- The client sends only
extensions.persistedQuery.sha256Hash(noquery). If the server does not know the hash → it responds with aPersistedQueryNotFounderror. - The client retries with the full
queryand the hash. The server verifiessha256(query) == hash, stores the query in theapqcache and returns the data. - Subsequent requests carrying only the hash hit the cache and return data without sending the query.
Configuration
Stores → Configuration → General → Automatic Persisted Queries — the HTTP codes returned in edge cases (matching apollo-server behaviour):
| Field | Default |
|---|---|
| HTTP code — query not found (GET) | 400 |
| HTTP code — query not found (POST) | 500 |
| HTTP code — invalid SHA (GET) | 400 |
| HTTP code — invalid SHA (POST) | 500 |
The apq (Automatic Persisted Queries) cache type appears in System → Cache Management —
that is also where you clear the remembered queries.
License
MIT (same as upstream). Fork maintained by SISL.
Maintained by SISL
Maintained fork by SISL — Magento 2 development and modules. More self-hosted plugins: SISL Marketplace.