PHPackages                             scandipwa/persisted-query - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. scandipwa/persisted-query

ActiveMagento2-module

scandipwa/persisted-query
=========================

ScandiPWA persisted query module

3.1.1(3y ago)12244.5k—9.8%17[2 issues](https://github.com/scandipwa/persisted-query/issues)[3 PRs](https://github.com/scandipwa/persisted-query/pulls)3OSL-3.0PHP

Since Mar 8Pushed 2y ago5 watchersCompare

[ Source](https://github.com/scandipwa/persisted-query)[ Packagist](https://packagist.org/packages/scandipwa/persisted-query)[ RSS](/packages/scandipwa-persisted-query/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (42)Used By (3)

ScandiPWA persisted query
=========================

[](#scandipwa-persisted-query)

The main goal of persisted query approach is to reduce the amount of data transfered from the client to the server within a POST body containing GraphQl Document. However, current module extends the usage of persisted queries to actually cache the responses in Varnish or CDN node for fast responses. (avg. 5ms vs 5000ms on dev machine)

Prerequisites
-------------

[](#prerequisites)

1. Varnish
2. Redis
3. PHP ext-phpredis is suggested for faster serialization and deserialization

Config
------

[](#config)

### magento setup:config:set

[](#magento-setupconfigset)

For the convenience there are additional flags available for `php bin/magento setup:config:set` command:

`--pq-host`\[mandatory\] - persisted query redis host (`redis` for ScandiPWA docker setup)

`--pq-port`\[mandatory\] - persisted query redis port (`6379` for ScandiPWA docker setup)

`--pq-database`\[mandatory\] - persisted query redis database (`5` for ScandiPWA docker setup)

`--pq-scheme`\[mandatory\] - persisted query redis scheme

`--pq-password`\[optional, **empty password is not allowed**\] - persisted query redis password

### Manual configuration

[](#manual-configuration)

Configuration for custom Redis storage, where hashes and GraphQl documents are kept in environment config (`app/etc/env.php`) -&gt; `cache/persisted-query` and can be configured manually:

```
	'persisted-query' => [
		'redis' => [
			'host' => 'redis',
			'scheme' => 'tcp',
			'port' => '6379',
			'database' => '5'
		]
	]

```

Cache control
-------------

[](#cache-control)

Available from v1.3.0

CLI command `magento cache:flush` and admin panel `Cache Management` has necessary logic to flush GraphQl responses stored in varnish.

`persisted_query_response` - can be disabled, controls `varnish` caches (graphql response caches).

`bin/magento scandipwa:pq:flush` - flushes persisted query REDIS storage(query body)

Usage
-----

[](#usage)

Dynamic persisted query suppose Client to register unknown queries with a series of request-response.

Recommended usage:

1. Optimistically request query execution, referencing query by hash, passing necessary query variables as request parameters: `GET  /graphql?hash=135811058&hideChildren=true`
2. Server has multiple options:

- respond with resolved query (status code `200`)
- respond with Unknown query error (status code `410`)

3. Status code `410` - client must issue PUT request, with the same hash and **entire GraphQl query document within the body**. `PUT /graphql?hash=135811058`
4. Server responds with status code `201` on successful query registration.
5. Server will now executes the registered query referenced by hash`GET /graphql?hash=135811058`

In order to effectively utilize persisted query mechanism and avoid unnecessary time-consuming request-response interactions GraphQl query must utilize variables.

### Variables

[](#variables)

Variables must be passed in pseudo-json format. You must keep the structure, but skip usage of quotes.

#### Array

[](#array)

Array is a list of values, separated with coma, i.e.: `cmsBlocks_identifiers=homepage-promo-categories,homepage-top-items,homepage-about-us`

Let's consider the details: `cmsBlocks_identifiers` - GraphQl variable name `homepage-promo-categories,homepage-top-items,homepage-about-us` - Array of values

#### Complex structures

[](#complex-structures)

Complex structures must keep structures described with special chars `{`, `}`, `:`. Array within complex structs MUST use special chars: `[`, `]`.

Example:

`_filter={category_url_path:{eq:men},max_price:{lteq:300},color:{in:[74,75]}}`Let's consider the details: `_filter` - GraphQl variable name `{ category_url_path: { eq:men }, max_price:{ lteq:300 }, color:{ in:[74,75] } }` - "Object", passed as GET parameter. It has not quotation marks, as these are automatically added by the server during the processing.

---

### Examples

[](#examples)

Query body:

`query ($cmsBlocks_identifiers:[String]) {cmsBlocks:cmsBlocks(identifiers:$cmsBlocks_identifiers){ items{ title, content, identifier } }}`

Request URI:

`GET /graphql?hash=2443957263&cmsBlocks_identifiers=homepage-promo-categories,homepage-top-items,homepage-about-us`

---

Query body:

`"query ($_currentPage:Int!, $_pageSize:Int!, $_filter:ProductFilterInput!, $category_url_path:String!) {products(currentPage:$_currentPage, pageSize:$_pageSize, filter:$_filter){ total_count, items{ id, name, short_description, url_key, special_price, sku, categories{ name, url_path, breadcrumbs{ category_name, category_url_key } }, price{ regularPrice{ amount{ value, currency } }, minimalPrice{ amount{ value, currency } } }, thumbnail, thumbnail_label, small_image, small_image_label, brand, color, size, shoes_size, type_id }, filters{ name, request_var, filter_items{ label, value_string, ... on SwatchLayerFilterItem { label, swatch_data{ type, value } } } } }, category:category(url_path:$category_url_path){ id, name, description, url_path, image, url_key, product_count, meta_title, meta_description, breadcrumbs{ category_name, category_url_key, category_level }, children{ id, name, description, url_path, image, url_key, product_count, meta_title, meta_description, breadcrumbs{ category_name, category_url_key, category_level } } }}"`

Request URI:

`https://scandipwa.local/graphql?hash=1713013963&_currentPage=1&_pageSize=12&_filter={category_url_path:{eq:men},max_price:{lteq:300}}&category_url_path=men`

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~38 days

Recently: every ~110 days

Total

40

Last Release

1133d ago

Major Versions

1.4.3 → 2.0.02019-07-29

1.4.7 → 2.0.12019-10-18

1.5.0 → 2.1.02019-10-28

1.5.1 → 2.1.22020-01-22

2.5.2 → 3.0.02020-11-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c2cd642b3c520df20394344ee587782e246262899e7ddc99a191360e85d7fdc?d=identicon)[scandiweb](/maintainers/scandiweb)

---

Top Contributors

[![alfredsgenkins](https://avatars.githubusercontent.com/u/29531824?v=4)](https://github.com/alfredsgenkins "alfredsgenkins (20 commits)")[![dfelton](https://avatars.githubusercontent.com/u/2659558?v=4)](https://github.com/dfelton "dfelton (5 commits)")[![AleksandrsKondratjevs](https://avatars.githubusercontent.com/u/68007919?v=4)](https://github.com/AleksandrsKondratjevs "AleksandrsKondratjevs (5 commits)")[![carinadues](https://avatars.githubusercontent.com/u/82165392?v=4)](https://github.com/carinadues "carinadues (4 commits)")[![eli-l](https://avatars.githubusercontent.com/u/7448649?v=4)](https://github.com/eli-l "eli-l (2 commits)")[![AzizKHAN030](https://avatars.githubusercontent.com/u/76899788?v=4)](https://github.com/AzizKHAN030 "AzizKHAN030 (2 commits)")[![korbax](https://avatars.githubusercontent.com/u/225603?v=4)](https://github.com/korbax "korbax (1 commits)")[![NiklasBr](https://avatars.githubusercontent.com/u/279826?v=4)](https://github.com/NiklasBr "NiklasBr (1 commits)")[![raivisdejus](https://avatars.githubusercontent.com/u/5319134?v=4)](https://github.com/raivisdejus "raivisdejus (1 commits)")[![xapiksw](https://avatars.githubusercontent.com/u/52314930?v=4)](https://github.com/xapiksw "xapiksw (1 commits)")

### Embed Badge

![Health badge](/badges/scandipwa-persisted-query/health.svg)

```
[![Health](https://phpackages.com/badges/scandipwa-persisted-query/health.svg)](https://phpackages.com/packages/scandipwa-persisted-query)
```

###  Alternatives

[fastly/magento2

Fastly CDN Module for Magento 2.4.x

1564.2M1](/packages/fastly-magento2)[smile/elasticsuite

Magento 2 merchandising and search engine built on ElasticSearch

8044.5M33](/packages/smile-elasticsuite)[adyen/module-payment

Official Magento2 Plugin to connect to Payment Service Provider Adyen.

1663.0M10](/packages/adyen-module-payment)[dotdigital/dotdigital-magento2-extension

Dotdigital for Magento 2

50374.2k18](/packages/dotdigital-dotdigital-magento2-extension)[graycore/magento2-graphql-introspection-cache

1015.2k](/packages/graycore-magento2-graphql-introspection-cache)[mage-os/module-inventory-reservations-grid

Add a grid with the list of inventory reservations.

126.8k](/packages/mage-os-module-inventory-reservations-grid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
