wp-graphql-cache icon indicating copy to clipboard operation
wp-graphql-cache copied to clipboard

Caching queries with variables

Open hatsumatsu opened this issue 3 years ago • 1 comments

Thanks for this plugin!

I was wondering how caching a named query with query variables works. Let's say I have a paginated query using the after filter.

query MyPosts( $after: String ) {
  posts(after: $after, first: 10) {
    edges {
      node {
        title
      }
    }
  }
}

Would caching query MyPosts (see below) automatically handle different versions of the query based on the passed variables? Or does it ignore variables all together?

use WPGraphQL\Extensions\Cache\CacheManager;

CacheManager::register_graphql_query_cache([
    'query_name' => 'MyPosts',
    'expire' => 120,
]);

hatsumatsu avatar Mar 24 '21 07:03 hatsumatsu

seems like would ignore them? I think this would be a very useful feature

blocka avatar Jun 13 '21 13:06 blocka