From 25c98ec0cab10056b24ad7285ca1143d68f576a6 Mon Sep 17 00:00:00 2001 From: hsimah Date: Mon, 4 Jan 2021 14:23:37 -0800 Subject: [PATCH] Origin/feature/update dependencies (#21) * update deprecated function calls * update version --- README.md | 8 +++++--- class-facetwp.php | 10 +++++----- wp-graphql-facetwp.php | 10 +++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f79235a..fd1998f 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ Download and install like any WordPress plugin. The WPGraphQL documentation can be found [here](https://docs.wpgraphql.com). The FacetWP documentation can be found [here](https://facetwp.com/documentation/). -- Requires WPGraphQL 0.8.1+ -- Requires FacetWP 3.5.2.1+ +- Requires WPGraphQL 1.0.4+ +- Requires FacetWP 3.5.7+ ## Overview This plugin exposes configured facets through the graph schema. Once registered for a type, a query is available. The payload includes both facet choices and information and a connection to the post type data. This allows for standard GraphQL pagination of the returned data set. @@ -22,7 +22,9 @@ This plugin has been tested and is functional with SearchWP. To register a FacetWP query in the WPGraphQL schema for a WordPress post type (eg `post`) simply call the following function: ``` // Register facet for Posts -register_graphql_facet_type( 'post' ); +add_action( 'graphql_register_types', function () { + register_graphql_facet_type( 'post' ); +} ); ``` This will create a WPGraphQL `postFacet` field on the `RootQuery`. The payload includes a collection of queried `facets` and a `posts` connection. The connection is a standard WPGraphQL connection supporting pagination and server side ordering. The connection payload only includes filtered posts. diff --git a/class-facetwp.php b/class-facetwp.php index 171b9e7..fd90695 100644 --- a/class-facetwp.php +++ b/class-facetwp.php @@ -201,14 +201,14 @@ private function register_facet_connection($config) 'toType' => $singular, 'fromFieldName' => lcfirst($plural), 'connectionArgs' => PostObjects::get_connection_args(), - 'resolveNode' => function ($node, $_args, $context, $_info) { - return !empty($node) ? DataSource::resolve_post_object($node->ID, $context) : null; + 'resolveNode' => function ($node, $_args, $context) { + return $context->get_loader('post')->load_deferred($node->ID); }, 'resolve' => function ($source, $args, $context, $info) use ($type) { $resolver = new PostObjectConnectionResolver($source, $args, $context, $info, $type); - $resolver->setQueryArg('post__in', $source['results']); - - return $resolver->get_connection(); + return $resolver + ->set_query_arg('post__in', $source['results']) + ->get_connection(); }, ]); } diff --git a/wp-graphql-facetwp.php b/wp-graphql-facetwp.php index a1be9b3..7431f21 100644 --- a/wp-graphql-facetwp.php +++ b/wp-graphql-facetwp.php @@ -2,18 +2,18 @@ /** * Plugin Name: WP GraphQL FacetWP - * Plugin URI: https://github.com/hsimah/wp-graphql-facetwp + * Plugin URI: https://github.com/hsimah-services/wp-graphql-facetwp * Description: WP GraphQL provider for FacetWP * Author: hsimah * Author URI: http://www.hsimah.com - * Version: 0.1.1 + * Version: 0.2.0 * Text Domain: wpgraphql-facetwp * License: GPL-3 * License URI: https://www.gnu.org/licenses/gpl-3.0.html * * @package WPGraphQL_FacetWP * @author hsimah - * @version 0.1.1 + * @version 0.2.0 */ // Exit if accessed directly. @@ -29,8 +29,8 @@ add_action('admin_init', function () { $versions = [ - 'wp-graphql' => '0.8.1', - 'facetwp' => '3.5.2.1', + 'wp-graphql' => '1.0.4', + 'facetwp' => '3.5.7', ]; if (