⬡ GraphQL Intermediate

What are persisted queries in GraphQL?

Answer

Persisted queries are a performance and security optimization where the client sends only a hash of the query rather than the full query string. The server maps hashes to pre-registered query documents. Benefits include smaller request payloads (especially for large queries), improved CDN and GET-request caching (the full query no longer needs to be in the URL), and enhanced security — you can whitelist only known query hashes, preventing arbitrary queries from being executed (useful in production). Apollo Client supports automatic persisted queries (APQ), which fall back to the full query if the server does not recognize the hash.