WPGraphQL Persisted Queries
Community PluginView Plugin on Github
Persisted GraphQL queries allow a GraphQL client to optimistically send a hashof the query instead of the full query; if the server has seen the query before, it can satisfy the request. This saves network overhead and makes it possible to move to
GETrequests instead of
POST. The primary benefit of
GETrequests is that they can be cached at the edge (e.g., with Varnish).
This plugin requires WPGraphQL 0.2.0 or newer.
Apollo Client provides an easy implementation of persisted queries:
This plugin aims to be compatible with that implementation, but will work withany client that sends a
query. Make sure your client also sends
operation_namewith the optimistic request.
When the client provides a query hash or ID, that query will be persisted in acustom post type. By default, this post type will not be visible in the dashboard.
Query IDs are case-insensitive (i.e.,
myquery are equivalent).
This plugin does nothing to implement, amend, or purge page (edge) caching. Itis up to you to make page caching work for you. Remember that WPGraphQL has a single monolithic endpoint at
/graphqland persisted query requests will arrive as
GETrequests to that endpoint with unique query strings. Cache wisely!
- The custom post type used to persist queries. If empty, queries will not be persisted.
- Args passed to register_post_type for custom post type. Filter to expose the custom post type in the admin UI or in GraphQL:
- Override the default query loading implementation.
- Override the query (post data) that will be persisted.