Skip to content

Commit

Permalink
release: 0.4.0 (#39)
Browse files Browse the repository at this point in the history
* chore: fix description field type in bug report template

* chore: update deps

* chore: version bump

* chore: update README.md

* chore: update plugin headers

* chore!: bump minimum version of FacetWP

* chore: update changelog
  • Loading branch information
justlevine authored Sep 28, 2022
1 parent 5084ddb commit babeb4e
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >-
Expand Down
19 changes: 13 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
154 changes: 108 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,59 @@
![Logo](./logo.png)
# 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+
![Packagist License](https://img.shields.io/packagist/l/hsimah-services/wp-graphql-facetwp?color=green) ![Packagist Version](https://img.shields.io/packagist/v/hsimah-services/wp-graphql-facetwp?label=stable) ![GitHub commits since latest release (by SemVer)](https://img.shields.io/github/commits-since/hsimah-services/wp-graphql-facetwp/0.4.0) ![GitHub forks](https://img.shields.io/github/forks/hsimah-services/wp-graphql-facetwp?style=social) ![GitHub Repo stars](https://img.shields.io/github/stars/hsimah-services/wp-graphql-facetwp?style=social)<br />
![CodeQuality](https://img.shields.io/github/workflow/status/hsimah-services/wp-graphql-facetwp/Code%20Quality?label=Code%20Quality)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/hsimah-services/wp-graphql-facetwp/Integration%20Testing?label=Integration%20Testing)
![Coding Standards](https://img.shields.io/github/workflow/status/hsimah-services/wp-graphql-facetwp/WordPress%20Coding%20Standards?label=WordPress%20Coding%20Standards)

-----
## 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)._ <br />
- _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:
```
Expand All @@ -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 WPGraph<strong>i</strong>QL 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
Expand All @@ -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
Expand All @@ -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.
20 changes: 12 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => 'd71dd9f962310739c1bf8c0a1219d2b9d577d4cf',
'reference' => 'caf3575b160798a38bb6d6eeed99e0e4093cebfb',
'name' => 'hsimah-services/wp-graphql-facetwp',
'dev' => false,
),
Expand All @@ -16,7 +16,7 @@
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => 'd71dd9f962310739c1bf8c0a1219d2b9d577d4cf',
'reference' => 'caf3575b160798a38bb6d6eeed99e0e4093cebfb',
'dev_requirement' => false,
),
),
Expand Down
16 changes: 8 additions & 8 deletions wp-graphql-facetwp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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 = [];

Expand Down

0 comments on commit babeb4e

Please sign in to comment.