Description
The terms "persisted queries" and "stored operations" are typically used interchangably. The traditional name is "persisted queries", but the term "stored operations" acknowledges that this approach can be used with mutation and subscription operations in addition to queries.
There's lots of different implementations of this feature, often with different aims. Sometimes it's used to block all but a small allow-list of operations. Sometimes it's used to reduce network bandwidth for GraphQL requests. Sometimes it's used to improve HTTP cacheability (GET requests with short URLs).
Relevant links:
- https://relay.dev/docs/guides/persisted-queries/
- https://www.apollographql.com/docs/apollo-server/performance/apq/
- https://github.com/graphile/persisted-operations
- https://chillicream.com/docs/hotchocolate/v13/performance/persisted-queries/
- https://chillicream.com/docs/hotchocolate/v13/performance/automatic-persisted-queries
- https://github.com/restorando/graphql-query-whitelist
Some implementations require queries to be persisted to the server in advance of receiving queries (e.g. at build time); others negotiate the storage of the query with the server for bandwidth optimisation (e.g. automatic persisted queries).
Typically persisted queries replace the query
in {query, variables, operationName}
with another field (typically id
) that indicates an identifier for the operation - perhaps a number or hash.
Typically stored operations remove the query
in {query, variables, operationName}
and instead indicate the operation via a hash or similar identifier in the extensions
property.
One of the optimisations that stored operations enable is that the parse
and validate
steps of GraphQL execution can be performed once per stored operation and cached; future requests for the same stored operation can jump straight to the execute
step.