GraphQL persisted queries: send an ID and enforce an operation safelist
A GraphQL persisted query links an operation document to an identifier in server storage, so requests can send the identifier instead of the full query text. Automatic persisted queries (APQ) are primarily a cache technique that reduces request size. Trusted documents or a safelist are policies that restrict execution to operations approved in advance. Sending a hash alone does not restrict an API to an allowlist.
A GraphQL persisted query links an operation document to an identifier in server storage, so requests can send the identifier instead of the full query text. Automatic persisted queries (APQ) are primarily a cache technique that reduces request size. Trusted documents or a safelist are policies that restrict execution to operations approved in advance. Sending a hash alone does not restrict an API to an allowlist.
This article covers APQ and pre-registered operations in HTTP-based GraphQL requests. Registration details and protocols vary by client and server; Apollo examples below apply to those products.
How persisted queries work
The server stores a complete GraphQL document under a stable ID. The client later sends the ID and variables; the server looks up, validates, and executes the stored document. Apollo APQ uses the SHA-256 hash of the query string as its ID. For large documents, sending an ID can reduce request text in a body or URL and lower network usage. It does not automatically reduce response size or resolver and database work.
A typical Apollo APQ exchange works like this:
The client sends only the hash and variables.
If the server cache has no matching hash, it returns `PERSISTED_QUERY_NOT_FOUND`.
The client retries with the same hash and the full query document.
The server receives the document, checks that it matches the hash, stores it, and executes it.
Later requests can use the cached document by sending only the hash and variables.
APQ therefore requires the full document to reach the server at least once. Cache expiration or eviction can make a previously known hash unknown again, so verify client fallback behavior and cache consistency.
APQ, persisted operations, and trusted documents
Terminology varies across implementations. “Persisted query” can refer to anything from APQ to a security allowlist, so check the actual behavior.
| Approach | When it is registered | Unknown ID or document | Main purpose |
|---|---|---|---|
| APQ cache | Dynamically, when a client first sends the full document | The client may retry with the full text when the document is missing | Reduce request size and repeated transmission |
| Pre-registered persisted operation | A manifest or list is registered during build or deployment | Can be configured to reject operations outside the list | Restrict approved client operations and allow ID-based requests |
| Trusted document / safelist | Reviewed and approved documents are added to a server list | Can reject documents outside the list, depending on policy | Limit executable documents for trusted apps |
The security effect depends on whether the server actually blocks arbitrary documents. Apollo GraphOS Router, for example, distinguishes security levels such as allowing operation IDs, auditing, and safelisting. A mode where clients may use IDs but arbitrary documents are still accepted is not an enforced safelist. Check the product and configuration to distinguish “registered” from “registration enforced.”
Do not assume pre-registration suits a public API where third-party developers can submit arbitrary operations. The GraphQL security guide describes trusted documents as a fit for first-party apps whose operations developers authored and reviewed; third-party public clients cannot all be known in advance. Even with a safelist, use separate defenses such as authentication, authorization, page-size, depth and complexity limits, and rate limits.
Implementation steps
For request-size reduction, start by checking APQ. Confirm that the current client and server support the same APQ version and hash rules. Decide whether the client may resend the full document after a cache miss. For a public or mixed-use API, that fallback can allow arbitrary documents to reach the server.
To restrict executable operations, prepare registration and enforcement together. Generate a manifest from the operations and fragments used by the build, then publish it to the server’s allowlist through CI/CD or deployment. Enable rejection of query strings outside the list, and verify that client IDs and headers match server policy. A hash identifies a document; it is not authorization or a secret key.
Plan release and rollback. If clients ship before the server accepts the new manifest, new IDs may fail. A safer general order is to publish registrations first, deploy clients next, and remove unused operations after older clients are retired. Verify the actual deployment sequence and compatibility rules for your product.
Check hash mismatches. The same intended operation can produce different hashes if string normalization, fragment assembly, or tool options differ. Ensure the manifest generator and runtime client use the same source operations and ID-generation settings. Monitor unknown IDs and mismatches. Apollo’s documentation says PQL IDs should be unique and derived from the document, not from the operation name.
What to verify
The response to an unknown hash and the client’s full-document fallback
Whether the server truly rejects unapproved query strings
Whether server, client, and manifest generate identical hashes
Whether variables continue to travel separately from the operation document
The order of registration, client rollout, and cleanup of old entries
Cache eviction, sharing across server instances, list versioning, and recovery
Authentication, object and field authorization, cost controls, and rate limits beyond operation restrictions
Persisted queries can reduce the transmission of large operation strings, while a pre-approved list can restrict executable documents when enforcement is enabled. Choose based on performance goals and the trust model, then verify from server configuration and failure responses that requests are limited to registered IDs when that is the intent.
Sources
[GraphQL performance guide: persisted queries](https://graphql.org/learn/performance/)
[GraphQL security guide: trusted documents](https://graphql.org/learn/security/)
[Apollo Server APQ documentation](https://www.apollographql.com/docs/apollo-server/performance/apq)
[Apollo client guide to persisted queries](https://www.apollographql.com/docs/react/data/persisted-queries)
[Apollo GraphOS persisted-query safelisting](https://www.apollographql.com/docs/graphos/platform/security/persisted-queries)
[GraphQL over HTTP announcement: persisted-document standardization status](https://graphql.org/blog/2026-11-12-announcing-the-graphql-over-http-spec/)