-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of Root Entry points for GuestCommenter (prev …
…CommentAuthor)
- Loading branch information
1 parent
b1e1b3a
commit 8020c21
Showing
17 changed files
with
273 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace WPGraphQL\Connection; | ||
|
||
use WPGraphQL\Data\Connection\GuestCommenterConnectionResolver; | ||
|
||
|
||
/** | ||
* Class Comments | ||
* | ||
* This class organizes the registration of connections to Comments | ||
* | ||
* @package WPGraphQL\Connection | ||
*/ | ||
class GuestCommenters { | ||
|
||
/** | ||
* Register connections to Guest Commenters. | ||
* | ||
* Connections from Root Query to Guest Commenters . | ||
* | ||
* @return void | ||
* @throws Exception | ||
*/ | ||
public static function register_connections() { | ||
|
||
/** | ||
* Register connection from RootQuery to Guest Commenters | ||
*/ | ||
register_graphql_connection( self::get_connection_config() ); | ||
} | ||
|
||
/** | ||
* Given an array of $args, this returns the connection config, merging the provided args | ||
* with the defaults | ||
* | ||
* @param array $args | ||
* | ||
* @return array | ||
*/ | ||
public static function get_connection_config( $args = [] ) { | ||
$defaults = [ | ||
'fromType' => 'RootQuery', | ||
'toType' => 'GuestCommenter', | ||
'fromFieldName' => 'guestCommenters', | ||
'connectionArgs' => self::get_connection_args(), | ||
'resolve' => function ( $source, $args, $context, $info ) { | ||
|
||
$resolver = new GuestCommenterConnectionResolver( $source, $args, $context, $info ); | ||
|
||
return $resolver->get_connection(); | ||
|
||
}, | ||
]; | ||
|
||
return array_merge( $defaults, $args ); | ||
} | ||
|
||
/** | ||
* This returns the connection args for the Comment connection | ||
* | ||
* @return array | ||
*/ | ||
public static function get_connection_args() { | ||
return [ | ||
'authorEmail' => [ | ||
'type' => 'String', | ||
'description' => __( 'Guest commenter email address.', 'wp-graphql' ), | ||
], | ||
'authorIn' => [ | ||
'type' => [ | ||
'list_of' => 'ID', | ||
], | ||
'description' => __( 'Array of author IDs to include comments for.', 'wp-graphql' ), | ||
], | ||
'authorNotIn' => [ | ||
'type' => [ | ||
'list_of' => 'ID', | ||
], | ||
'description' => __( 'Array of author IDs to exclude comments for.', 'wp-graphql' ), | ||
], | ||
// 'orderby' => [ | ||
// 'type' => 'CommentsConnectionOrderbyEnum', | ||
// 'description' => __( 'Field to order the comments by.', 'wp-graphql' ), | ||
// ], | ||
// 'order' => [ | ||
// 'type' => 'OrderEnum', | ||
// 'description' => __( 'The cardinality of the order of the connection', 'wp-graphql' ), | ||
// ], | ||
// 'search' => [ | ||
// 'type' => 'String', | ||
// 'description' => __( 'Search term(s) to retrieve matching comments for.', 'wp-graphql' ), | ||
// ], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace WPGraphQL\Data\Connection; | ||
|
||
/** | ||
* Class CommentConnectionResolver | ||
* | ||
* @package WPGraphQL\Data\Connection | ||
*/ | ||
class GuestCommenterConnectionResolver extends CommentConnectionResolver { | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function get_query_args() { | ||
|
||
$query_args = parent::get_query_args(); | ||
|
||
$query_args['user_id'] = 0; | ||
|
||
return apply_filters( 'graphql_guest_commenter_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info ); | ||
} | ||
|
||
/** | ||
* Return the name of the loader | ||
* | ||
* @return string | ||
*/ | ||
public function get_loader_name() { | ||
return 'guest_commenter'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
namespace WPGraphQL\Type\Enum; | ||
|
||
class GuestCommenterIdTypeEnum { | ||
|
||
/** | ||
* Register the Enum used for setting the field to identify User nodes by | ||
* | ||
* @return void | ||
*/ | ||
public static function register_type() { | ||
register_graphql_enum_type( | ||
'GuestCommenterIdTypeEnum', | ||
[ | ||
'description' => __( 'The Type of Identifier used to fetch a single GuestCommenter node. To be used along with the "id" field. Default is "ID".', 'wp-graphql' ), | ||
'values' => self::get_values(), | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Returns the values for the Enum. | ||
* | ||
* @return array | ||
*/ | ||
public static function get_values() { | ||
return [ | ||
'ID' => [ | ||
'name' => 'ID', | ||
'value' => 'global_id', | ||
'description' => __( 'The hashed Global ID', 'wp-graphql' ), | ||
], | ||
'DATABASE_ID' => [ | ||
'name' => 'DATABASE_ID', | ||
'value' => 'database_id', | ||
'description' => __( 'The Database ID for the node', 'wp-graphql' ), | ||
] | ||
]; | ||
} | ||
} |
Oops, something went wrong.