GraphQL proxy
The browser never talks to Magento. Client-side GraphQL goes to /api/graphql on the storefront, a thin proxy that forwards only operations the storefront itself defines.
Persisted-query allowlist
Section titled “Persisted-query allowlist”At startup the proxy hashes every GraphQL document the engine defines. An incoming operation is normalised the same way and hashed. Anything without a matching hash gets 403.
- Documents are normalised before hashing: whitespace is reprinted and the
__typenamefields Apollo adds are removed. The storefront’s own requests always match. - A request may batch at most 10 operations. The storefront never batches, so a large batch is only ever abuse.
- Server-only operations, such as CMS block queries, are kept off the allowlist. Only server components run them, over the private network.
- The allowlist is enforced in production only, so GraphQL tools keep working during development.
A hand-written query, an introspection query or a query copied from another site is rejected before it reaches Magento.
Turnstile
Section titled “Turnstile”Abuse-prone operations need a Cloudflare Turnstile token: sign-in, registration, contact, newsletter, guest order and return lookup, guest tickets. The proxy verifies each token with Cloudflare and checks:
success;action, which ties the token to the form that produced it;hostname, againstTURNSTILE_HOSTNAMES.
Rejections are logged as [graphql proxy] turnstile <reason>. See Configuration for the two halves of the setup.
Caching
Section titled “Caching”A POST to /api/graphql is never cached: it carries customer tokens and mutations. nginx sets Cache-Control: no-store on it and caps the request body.
Guest reads go out as a hashed GET instead: an allowlisted query named by its hash, with no token or cookie forwarded, so one answer is right for every guest.
- By default nginx’s
graphql_getzone keeps each answer 60 seconds. - With
SF_CACHE_GRAPHQL=1(on top of the shared store:SF_CACHE_NEXT=1andREDIS_URL), the proxy asks Magento by GET, keeps the answer in Valkey with the tags Magento sends (X-Magento-Tags), and deletes it when a Magento PURGE names one of those tags. An answer stays fresh for up to 6 hours, never past local midnight, and is then served once more while one request refreshes it. nginx keeps it 2 seconds. Only a clean200with tags is stored. - The
X-Storefront-Cacheresponse header says what happened:HIT,STALE,MISS, orBYPASS(not stored). - A purge is recorded with its time, and every read checks that record. An answer asked of Magento before one of its tags was purged is a miss, even when Valkey evicted the list of answers carrying that tag (it evicts any key under memory pressure), and even when the answer was written after the purge.
- If Valkey stops answering, the proxy falls back to asking Magento as before.
Signed-in shoppers send the same hashed GET with ctx=1. The proxy then forwards the customer’s token from the httpOnly cookie, as on POST, so group prices and catalog price rules apply, and answers private, no-store: the separate URL means nginx or a CDN can never hand a signed-in shopper a guest’s copy, or the reverse.
- With
SF_CACHE_CONTEXT=1the answer is also shared in Valkey between the shoppers of one pricing context: Magento’sX-Magento-Cache-Id, which follows the customer group, store and currency, never the customer. - A token’s context is learned only from Magento’s own clean answers to that token, kept 15 minutes under a hash of the token, and refreshed by every signed-in POST. A group change (leaving the first-order group after the first order, say) shows on the shopper’s next request to Magento; an admin change to a shopper who only browses cached answers shows within 15 minutes.
- An answer is stored only under the context Magento reported for it and only with Magento’s tags, so Magento’s PURGE reaches it like a guest answer. Fields Magento marks uncacheable come without tags and are never stored.
- Off, a signed-in GET goes to Magento with the token every time, the same as a POST.
- The public JSON routes built on
"use cache"data (/api/product-links,/api/brand-products,/api/product-blog-posts,/api/deals,/api/best-sellers) work the same way: withSF_CACHE_NEXT=1their data is purged in Valkey, so nginx keeps them 2 seconds instead of 300. The browser keeps 300 seconds either way.