
Feature:
Persisted Queries
Persisted Queries
In a REST API, we create multiple endpoints, each returning a pre-defined set of data. In a GraphQL API, in contrast, we provide any query to a single endpoint, which returns exactly the requested data.
Persisted queries are normal GraphQL queries, however they are stored in the server and accessed under their own URL, thus emulating a REST endpoint. They provide the advantages from these two APIs, while avoiding their disadvantages:
| Advantages | Disadvantages |
|---|---|
✅ Accessed via GET or POST | POST |
| ✅ Can be cached on the server or CDN | |
| ✅ It's secure: only intended data is exposed | |
| ✅ No under/over fetching of data, all data is retrieved in a single request | |
| ✅ It enables rapid iteration of the project | |
| ✅ It can be self-documented | |
| ✅ It provides clients to create and publish the query |
