Skip to content

Quartz/wp-graphql-persisted-queries

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

WPGraphQL Persisted Queries

Persisted GraphQL queries allow a GraphQL client to optimistically send a hash of 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 GET requests instead of POST. The primary benefit of GET requests is that they can be cached at the edge (e.g., with Varnish).

This plugin requires WPGraphQL 0.2.0 or newer.

Compatibility

Apollo Client provides an easy implementation of persisted queries:

https://github.com/apollographql/apollo-link-persisted-queries#automatic-persisted-queries

This plugin aims to be compatible with that implementation, but will work with any client that sends a queryId alongside the query. Make sure your client also sends operationName or operation_name with the optimistic request.

Implementation

When the client provides a query hash or ID, that query will be persisted in a custom post type. By default, this post type will not be visible in the dashboard.

Query IDs are case-insensitive (i.e., MyQuery and myquery are equivalent).

Caching

This plugin does nothing to implement, amend, or purge page (edge) caching. It is up to you to make page caching work for you. Remember that WPGraphQL has a single monolithic endpoint at /graphql and persisted query requests will arrive as GET requests to that endpoint with unique query strings. Cache wisely!

Filters

graphql_persisted_queries_post_type

  • Default: 'graphql_query'
  • The custom post type used to persist queries. If empty, queries will not be persisted.

graphql_persisted_queries_post_type_args

  • Args passed to register_post_type for custom post type. Filter to expose the custom post type in the admin UI or in GraphQL:

    query PersistedQueryQuery {
      persistedQueries {
        nodes {
          id
          title
          content(format: RAW)
        }
      }
    }
    

graphql_persisted_queries_load_query

  • Default: null
  • Override the default query loading implementation.

graphql_persisted_queries_save_query

  • Override the query (post data) that will be persisted.

About

[ALPHA] Implementation of persisted queries for WPGraphQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages