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.
Previous
What is the N+1 problem in GraphQL and how does DataLoader solve it?
Next
What is the difference between schema-first and code-first GraphQL approaches?
More GraphQL Questions
View all →- Intermediate What is the N+1 problem in GraphQL and how does DataLoader solve it?
- Intermediate What is the difference between schema-first and code-first GraphQL approaches?
- Intermediate What are the pagination strategies in GraphQL?
- Intermediate How is authentication handled in GraphQL?
- Intermediate How do you implement field-level authorization in GraphQL?