diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index 79a5c3e..439189a 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -9,7 +9,7 @@ body:
Please remember, a bug report is not the place to ask questions. You can
use Slack for that, or start a topic in [GitHub
Discussions](https://github.com/hsimah-services/wp-graphql-facetwp/discussions).
- - type: input
+ - type: textarea
attributes:
label: Description
description: >-
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 984e6a4..4f09813 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,11 +1,18 @@
# Changelog
-## Unreleased
-- feat!: Complete plugin refactor for v1.6.0+ compatibility.
-- chore!: Bump minimum PHP version to `v7.4`.
-- ci: Add GitHub Workflows.
-- repo: Add PR and Issue templates.
-- repo: Switch commit flow to `develop` => `main`. The existing `master` branch will be removed in the future.
+## v.0.4.0
+This _major_ release refactors the underlying PHP codebase, bringing with it support for the latest versions of WPGraphQL and FacetWP. Care has been taken to ensure there are _no breaking changes_ to the GraphQL schema.
+
+- feat!: Refactor plugin PHP classes and codebase structure to follow ecosystem patterns.
+- feat!: Bump minimum version of WPGraphQL to `v1.6.0`.
+- feat!: Bump minimum PHP version to `v7.4`.
+- feat!: Bump minimum FacetWP version to `v4.0`.
+- fix: Implement `WPVIP` PHP coding standards.
+- fix: Implement and meet `PHPStan` level 8 coding standards.
+- tests: Implement basic Codeception acceptance tests.
+- ci: Add Github workflows for PRs and releases.
+- chore: update Composer dependencies.
+- chore: switch commit flow to `develop` => `main` and set default branch to `develop`. The existing `master` branch will be removed on 1 October 2022.
## v0.3.0
- feat: Updates with default connection inputs and WooCommerce integration hooks.
diff --git a/README.md b/README.md
index 2127afe..f4380f4 100644
--- a/README.md
+++ b/README.md
@@ -1,23 +1,59 @@

-# WPGraphQL-FacetWP: WPGraphQL provider for FacetWP
+# WPGraphQL for FacetWP
-## Quick Install
-Download and install like any WordPress plugin.
+Adds WPGraphQL support for [FacetWP](https://facetwp.com/).
-## Documentation
-The WPGraphQL documentation can be found [here](https://docs.wpgraphql.com).
-The FacetWP documentation can be found [here](https://facetwp.com/documentation/).
+* [Join the WPGraphQL community on Slack.](https://join.slack.com/t/wp-graphql/shared_invite/zt-3vloo60z-PpJV2PFIwEathWDOxCTTLA)
+* [Documentation](#usage)
+-----
-- Requires WPGraphQL 1.6.0+
-- 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.
This plugin has been tested and is functional with SearchWP.
+## System Requirements
+
+* PHP 7.4+ || 8.0
+* WordPress 5.4.1+
+* WPGraphQL 1.6.0+ (1.9.0+ recommended)
+* FacetWP 4.0
+## Quick Install
+
+1. Install & activate [WPGraphQL](https://www.wpgraphql.com/).
+2. Install & activate [FacetWP](https://facetwp.com/).
+3. Download the [latest release](https://github.com/hsimah-services/wp-graphql-facetwp/releases) `.zip` file, upload it to your WordPress install, and activate the plugin.
+
+### With Composer
+
+```console
+composer require hsimah-services/wp-graphql-facetwp
+```
+## Updating and Versioning
+
+As we work towards a 1.0 Release, we will need to introduce **numerous** breaking changes. We will do our best to group multiple breaking changes together in a single release, to make it easier on developers to keep their projects up-to-date.
+
+Until we hit v1.0, we're using a modified version of [SemVer](https://semver.org/), where:
+
+* v0.**x**: "Major" releases. These releases introduce new features, and _may_ contain breaking changes to either the PHP API or the GraphQL schema
+* v0.x.**y**: "Minor" releases. These releases introduce new features and enhancements and address bugs. They _do not_ contain breaking changes.
+* v0.x.y.**z**: "Patch" releases. These releases are reserved for addressing issue with the previous release only.
+
## Usage:
-**It is assumed that facets have been configured**
+
+- _The WPGraphQL documentation can be found [here](https://docs.wpgraphql.com)._
+- _The FacetWP documentation can be found [here](https://facetwp.com/documentation/)._
+
+### Registering a facet to WPGraphQL
+
+**It is assumed that facets have been configured.**
To register a FacetWP query in the WPGraphQL schema for a WordPress post type (eg `post`) simply call the following function:
```
@@ -29,11 +65,20 @@ add_action( 'graphql_register_types', function () {
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.
-A simple query might look like this:
-```
-query GetPosts($query: FacetQueryArgs, $after: String, $search: String, $orderBy: [PostObjectsConnectionOrderbyInput]) {
- postFacet(where: {status: PUBLISH, query: $query}) {
- facets {
+### Example query
+
+
+**Note** This is not a complete list of GraphQL fields and types added to the schema. Please refer to the WPGraphiQL IDE for more queries and their documentation.
+
+```graphql
+query GetPostsByFacet( $query: FacetQueryArgs, $after: String, $search: String, $orderBy: [PostObjectsConnectionOrderbyInput] ) {
+ postFacet(
+ where: {
+ status: PUBLISH,
+ query: $query # The query arguments are determined by the Facet type.
+ }
+ ) {
+ facets { # The facet configuration
selected
name
label
@@ -43,7 +88,11 @@ query GetPosts($query: FacetQueryArgs, $after: String, $search: String, $orderBy
count
}
}
- posts(first: 10, after: $after, where: {search: $search, orderby: $orderBy}) {
+ posts ( # The results of the facet query. Can be filtered by WPGraphQL connection where args
+ first: 10,
+ after: $after,
+ where: { search: $search, orderby: $orderBy}
+ ) {
pageInfo {
hasNextPage
endCursor
@@ -57,43 +106,56 @@ query GetPosts($query: FacetQueryArgs, $after: String, $search: String, $orderBy
}
```
-## WooCommerce Support
+### WooCommerce Support
Support for WooCommerce Products can be added with following configuration:
```php
-add_action('graphql_register_types', function () {
- register_graphql_facet_type('product');
+add_action( 'graphql_register_types', function () {
+ register_graphql_facet_type( 'product' );
});
-add_filter('facetwp_graphql_facet_connection_config', function (array $default_graphql_config, array $config) {
- $type = $config['type'];
- $singular = $config['singular'];
- $field = $config['field'];
- $plural = $config['plural'];
-
- return [
- 'fromType' => $field,
- 'toType' => $singular,
- 'fromFieldName' => lcfirst($plural),
- 'connectionArgs' => Products::get_connection_args(),
- 'resolveNode' => function ($node, $_args, $context) use ($type) {
- return $context->get_loader($type)->load_deferred($node->ID);
- },
- 'resolve' => function ($source, $args, $context, $info) use ($type) {
- $resolver = new PostObjectConnectionResolver($source, $args, $context, $info, $type);
-
- if ($type === 'product') {
- $resolver = Products::set_ordering_query_args( $resolver, $args );
- }
-
- return $resolver
- ->set_query_arg('post__in', $source['results'])
- ->get_connection();
- },
- ];
-}, 100, 2);
+add_filter( 'facetwp_graphql_facet_connection_config',
+ function ( array $default_graphql_config, array $config ) {
+ $type = $config['type'];
+ $singular = $config['singular'];
+ $field = $config['field'];
+ $plural = $config['plural'];
+
+ return [
+ 'fromType' => $field,
+ 'toType' => $singular,
+ 'fromFieldName' => lcfirst( $plural ),
+ 'connectionArgs' => Products::get_connection_args(),
+ 'resolveNode' => function ( $node, $_args, $context) use ( $type ) {
+ return $context->get_loader( $type )->load_deferred( $node->ID );
+ },
+ 'resolve' => function ( $source, $args, $context, $info ) use ( $type ) {
+ $resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, $type);
+
+ if ( $type === 'product' ) {
+ $resolver = Products::set_ordering_query_args( $resolver, $args );
+ }
+
+ if( ! empty( $source['results'] ) ) {
+ $resolver->->set_query_arg( 'post__in', $source['results'] );
+ }
+
+ return $resolver ->get_connection();
+ },
+ ];
+ },
+ 100,
+ 2
+);
```
-## Limitations
+### Limitations
Currently the plugin only has been tested using Checkbox and Radio facet types. Support for additional types is in development.
+
+## Testing
+
+1. Update your `.env` file to your testing environment specifications.
+2. Run `composer install-test-env` to create the test environment.
+3. Run your test suite with [Codeception](https://codeception.com/docs/02-GettingStarted#Running-Tests).
+E.g. `vendor/bin/codecept run wpunit` will run all WPUnit tests.
diff --git a/composer.lock b/composer.lock
index 6374ae7..4ca28cf 100644
--- a/composer.lock
+++ b/composer.lock
@@ -6028,28 +6028,28 @@
},
{
"name": "softcreatr/jsonpath",
- "version": "0.7.5",
+ "version": "0.7.6",
"source": {
"type": "git",
"url": "https://github.com/SoftCreatR/JSONPath.git",
- "reference": "008569bf80aa3584834f7890781576bc7b65afa7"
+ "reference": "e04c02cb78bcc242c69d17dac5b29436bf3e1076"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/SoftCreatR/JSONPath/zipball/008569bf80aa3584834f7890781576bc7b65afa7",
- "reference": "008569bf80aa3584834f7890781576bc7b65afa7",
+ "url": "https://api.github.com/repos/SoftCreatR/JSONPath/zipball/e04c02cb78bcc242c69d17dac5b29436bf3e1076",
+ "reference": "e04c02cb78bcc242c69d17dac5b29436bf3e1076",
"shasum": ""
},
"require": {
"ext-json": "*",
- "php": ">=7.1"
+ "php": ">=7.1,<8.0"
},
"replace": {
"flow/jsonpath": "*"
},
"require-dev": {
"phpunit/phpunit": ">=7.0",
- "roave/security-advisories": "dev-master",
+ "roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
@@ -6072,7 +6072,7 @@
{
"name": "Sascha Greuel",
"email": "hello@1-2.dev",
- "homepage": "http://1-2.dev",
+ "homepage": "https://1-2.dev",
"role": "Developer"
}
],
@@ -6084,12 +6084,16 @@
"source": "https://github.com/SoftCreatR/JSONPath"
},
"funding": [
+ {
+ "url": "https://ecologi.com/softcreatr?r=61212ab3fc69b8eb8a2014f4",
+ "type": "custom"
+ },
{
"url": "https://github.com/softcreatr",
"type": "github"
}
],
- "time": "2021-06-02T22:15:26+00:00"
+ "time": "2022-09-27T09:27:12+00:00"
},
{
"name": "squizlabs/php_codesniffer",
diff --git a/readme.txt b/readme.txt
index f330ea7..ff1991f 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,12 +1,12 @@
=== WPGraphQL for FacetWP ===
-Contributors: hsimah
-Tags: GraphQL, Headless, Facet, FacetWP, WPGraphQL, WPGraphQL FacetWP
-Requires at least: 5.0
+Contributors: hsimah, axepress, justlevine
+Tags: GraphQL, Headless, WPGraphQL, Facet, FacetWP, WPGraphQL, FacetWP, React, Schema
+Requires at least: 5.4.1
Requires PHP: 7.4
-Requires FacetWP: 3.5.7
+Requires FacetWP: 4.0
Requires WPGraphQL: 1.6.0
-Tested up to: 6.0.1
-Stable tag: 0.3.0
+Tested up to: 6.0.2
+Stable tag: 0.4.0
Maintained at: https://github.com/hsimah-services/wp-graphql-facetwp
License: GPL-3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php
index 1e6a543..daa43f2 100644
--- a/vendor/composer/installed.php
+++ b/vendor/composer/installed.php
@@ -5,7 +5,7 @@
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
- 'reference' => 'd71dd9f962310739c1bf8c0a1219d2b9d577d4cf',
+ 'reference' => 'caf3575b160798a38bb6d6eeed99e0e4093cebfb',
'name' => 'hsimah-services/wp-graphql-facetwp',
'dev' => false,
),
@@ -16,7 +16,7 @@
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
- 'reference' => 'd71dd9f962310739c1bf8c0a1219d2b9d577d4cf',
+ 'reference' => 'caf3575b160798a38bb6d6eeed99e0e4093cebfb',
'dev_requirement' => false,
),
),
diff --git a/wp-graphql-facetwp.php b/wp-graphql-facetwp.php
index c1f4bd5..80da990 100644
--- a/wp-graphql-facetwp.php
+++ b/wp-graphql-facetwp.php
@@ -2,23 +2,23 @@
/**
* Plugin Name: WPGraphQL for FacetWP
* Plugin URI: https://github.com/hsimah-services/wp-graphql-facetwp
- * Description: WPGraphQL provider for FacetWP
+ * Description: Adds FacetWP support to WPGraphQL
* Author: hsimah
* Author URI: http://www.hsimah.com
- * Version: 0.3.0.1
+ * Version: 0.4.0
* Text Domain: wpgraphql-facetwp
- * Requires at least: 5.0
+ * Requires at least: 5.4.1
* Requires PHP: 7.4
* WPGraphQL requires at least: 1.6.0
- * FacetWP requires at least: 3.5.7
- * Tested up to: 6.0.1
+ * FacetWP requires at least: 4.0
+ * Tested up to: 6.0.2
* License: GPL-3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*
* @package WPGraphQL_FacetWP
* @author hsimah
* @license GPL-3
- * @version 0.3.0.1
+ * @version 0.4.0
*/
// Exit if accessed directly.
@@ -39,7 +39,7 @@
function graphql_facetwp_constants() : void {
// Plugin version.
if ( ! defined( 'WPGRAPHQL_FACETWP_VERSION' ) ) {
- define( 'WPGRAPHQL_FACETWP_VERSION', '0.3.0' );
+ define( 'WPGRAPHQL_FACETWP_VERSION', '0.4.0' );
}
// Plugin Folder Path.
@@ -72,7 +72,7 @@ function graphql_facetwp_constants() : void {
*/
function graphql_facetwp_deps_not_ready() : array {
$wpgraphql_version = '1.6.0';
- $facetwp_version = '3.5.7';
+ $facetwp_version = '4.0';
$deps = [];