API / Apollo Gateway Interview questions
What are Automatic Persisted Queries (APQ) and how do they work with Apollo Gateway?
Automatic Persisted Queries let a client send a short SHA-256 hash of a query instead of the full query text on every request, which matters especially for large federated operations sent over slow or mobile networks.
- The client computes a SHA-256 hash of the query and sends just the hash on the first attempt.
- If the gateway hasn't seen that hash before, it responds with a
PersistedQueryNotFounderror. - The client then resends the request, this time including both the hash and the full query text.
- The gateway caches the query text against that hash going forward.
- Every subsequent request for that operation only needs to send the short hash, since the gateway can look up the full text itself.
This shrinks the request payload substantially for repeat operations and, as a side benefit, gives operators a registry of exactly which query shapes are actually in use — useful for safelisting known operations in stricter production setups.
More Related questions...