GraphQL persisted query
A GraphQL persisted query is a GraphQL query that the server stores ahead of time. The client sends only an ID or hash, and the server runs the stored query. The request is shorter, and the server can limit callers to known operations.
How it works
A normal GraphQL request sends the query text and its variables. A persisted query request sends an ID or hash and the variables. The server looks up the stored query and runs it.
| Request style | What the client sends | What the server does |
|---|---|---|
| Plain GraphQL | Full query text and variables | Parses and runs the query |
| Persisted | Query ID or hash, and variables | Looks up the stored query and runs it |
| Automatic persisted queries (APQ) | Hash first, full text only if the server does not know it | Stores the text the first time it arrives |
Why it matters for AI agents
Many sites call GraphQL by hash. Replaying such a call needs the right hash and the right variables. A new deploy can change a hash, so a tool that hard-codes one can break. Read the hash from the site's own traffic rather than from memory.
Wield and persisted queries
Recipes may keep persisted query hashes. GraphQL mutations count as writes. A recipe must mark them as writes, and any write waits for your Allow before its first request leaves the browser.
Related terms
FAQ
Are persisted queries a security feature?
They can be. A server that accepts only stored queries cannot run arbitrary query text, which limits what a client can ask for. They do not replace authorization. The server still has to check who is calling and what that caller may read.
What is automatic persisted queries (APQ)?
APQ is a pattern from Apollo. The client sends the hash of a query. If the server does not know the hash, the client sends the full query text once. The server stores it under that hash and runs it. Later requests can send only the hash.
Sources
- GraphQL learngraphql.org
- Apollo persisted queriesapollographql.com