Skip to content

Commit

Permalink
Merge pull request #16 from AxeWP/hotfix/0.5.0.2
Browse files Browse the repository at this point in the history
Hotfix/0.5.0.2
justlevine authored Sep 19, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 732e8df + b5f7f8b commit b94c25b
Showing 7 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ Tested up to: 6.0.2
Requires PHP: 7.4
Requires Posts To Posts: 1.6.6
Requires WPGraphQL: 1.8.1
Stable tag: 0.5.0.1
Stable tag: 0.5.0.2
Maintained at: https://github.com/harness-software/wp-graphql-posts-to-posts
License: GPL-3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
2 changes: 1 addition & 1 deletion src/Mutations/AbstractMutation.php
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
abstract class AbstractMutation implements Hookable {

public function register_hooks() : void {
add_action( 'graphql_register_types_late', [ $this, 'register_input_fields' ] );
add_action( 'graphql_register_types', [ $this, 'register_input_fields' ] );
}

abstract public function register_input_fields() : void;
9 changes: 8 additions & 1 deletion src/Mutations/PostMutation.php
Original file line number Diff line number Diff line change
@@ -16,8 +16,15 @@ public function register_hooks(): void {
public function register_input_fields(): void {
$post_types = WPGraphQL::get_allowed_post_types( 'objects' );

$types_wtith_connections = Fields::get_post_types_with_connections();

foreach ( $post_types as $post_type ) {
$graphql_single_name = $post_type->graphql_single_name;
// Bail if no P2P connection registered for type.
if ( ! in_array( $post_type->name, $types_wtith_connections, true ) ) {
continue;
}

$graphql_single_name = ucfirst( $post_type->graphql_single_name );

register_graphql_field(
'Update' . $graphql_single_name . 'Input',
13 changes: 13 additions & 0 deletions src/Types/Fields.php
Original file line number Diff line number Diff line change
@@ -34,6 +34,19 @@ public static function get_p2p_connections() : array {
return array_filter( self::$p2p_connections, [ __CLASS__, 'should_create_connection' ] );
}

public static function get_post_types_with_connections() : array {
$connections = self::$p2p_connections;

$post_types = [];

foreach ( $connections as $name => $args ) {
$post_types[] = $args['from'];
$post_types[] = $args['to'];
}

return array_unique( $post_types );
}

public static function should_create_connection( array $connection ) : bool {
return self::should_connect_object( $connection['from'] )
&& self::should_connect_object( $connection['to'] );
9 changes: 8 additions & 1 deletion src/Types/Post.php
Original file line number Diff line number Diff line change
@@ -16,8 +16,15 @@ public function register_hooks() : void {
public function register_where_input_fields() : void {
$post_types = WPGraphQL::get_allowed_post_types( 'objects' );

$types_wtith_connections = Fields::get_post_types_with_connections();

foreach ( $post_types as $post_type ) {
$graphql_single_name = $post_type->graphql_single_name;
// Bail if no P2P connection registered for type.
if ( ! in_array( $post_type->name, $types_wtith_connections, true ) ) {
continue;
}

$graphql_single_name = ucfirst( $post_type->graphql_single_name );

register_graphql_field(
'RootQueryTo' . $graphql_single_name . 'ConnectionWhereArgs',
2 changes: 1 addition & 1 deletion src/Types/User.php
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
class User implements Hookable {

public function register_hooks() : void {
add_action( 'graphql_register_types_late', [ $this, 'register_where_input_fields' ] );
add_action( 'graphql_register_types', [ $this, 'register_where_input_fields' ] );
add_filter( 'graphql_map_input_fields_to_wp_user_query', [ $this, 'modify_query_input_fields' ], 10 );
}

2 changes: 1 addition & 1 deletion wp-graphql-posts-to-posts.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
/**
* Plugin Name: WPGraphQL for Posts 2 Posts
* Description: Creates WPGraphQL connections for all of your Posts 2 Posts connections.
* Version: 0.5.0.1
* Version: 0.5.0.2
* Author: Harness Software, Kellen Mace
* Author URI: https://harnessup.com/
* License: GPLv2 or later

0 comments on commit b94c25b

Please sign in to comment.