From 56bc31ca504fc6cb679eb48f2f45f4c2eac4d10c Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Tue, 28 Jan 2020 08:59:06 -0700 Subject: [PATCH 1/3] - WPGraphQL v0.6.0 regression - Update so that the `Types::` static methods aren't being called for Type definitions --- src/ManageTokens.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/ManageTokens.php b/src/ManageTokens.php index e77052d..a6b5da1 100644 --- a/src/ManageTokens.php +++ b/src/ManageTokens.php @@ -9,9 +9,6 @@ namespace WPGraphQL\JWT_Authentication; use GraphQL\Error\UserError; -use GraphQL\Type\Definition\Type; -use WPGraphQL\Model\User; -use WPGraphQL\Types; /** * Class - ManageToken @@ -25,7 +22,7 @@ public static function init() { add_action( 'graphql_register_types', [ __CLASS__, 'add_jwt_fields' ], 10 ); // Add fields to the input for user mutations. - add_filter( 'graphql_user_mutation_input_fields', [ __CLASS__, 'add_user_mutation_input_fields' ] ); + add_action( 'graphql_register_types', [ __CLASS__, 'add_user_mutation_input_fields' ] ); add_action( 'graphql_user_object_mutation_update_additional_data', [ __CLASS__, 'update_jwt_fields_during_mutation' ], 10, 3 ); // Filter the signed token, preventing it from returning if the user has had their JWT Secret revoked. @@ -150,20 +147,24 @@ public static function register_jwt_fields_to( $type ) { /** * Given an array of fields, this returns an array with the new fields added * - * @param array $fields The input fields for user mutations. - * * @return array */ - public static function add_user_mutation_input_fields( array $fields ) { - $fields['revokeJwtUserSecret'] = [ - 'type' => Types::boolean(), - 'description' => __( 'If true, this will revoke the users JWT secret. If false, this will unrevoke the JWT secret AND issue a new one. To revoke, the user must have proper capabilities to edit users JWT secrets.', 'wp-graphql-jwt-authentication' ), - ]; - $fields['refreshJwtUserSecret'] = [ - 'type' => Types::boolean(), - 'description' => __( 'If true, this will refresh the users JWT secret.' ), + public static function add_user_mutation_input_fields() { + $fields = [ + 'revokeJwtUserSecret' => [ + 'type' => 'Boolean', + 'description' => __( 'If true, this will revoke the users JWT secret. If false, this will unrevoke the JWT secret AND issue a new one. To revoke, the user must have proper capabilities to edit users JWT secrets.', 'wp-graphql-jwt-authentication' ), + ], + 'refreshJwtUserSecret' => [ + 'type' => 'Boolean', + 'description' => __( 'If true, this will refresh the users JWT secret.' ), + ], ]; + register_graphql_fields( 'RegisterUserInput', $fields ); + register_graphql_fields( 'CreateUserInput', $fields ); + register_graphql_fields( 'UpdateUserInput', $fields ); + return $fields; } From d3a04099e531ac08957789c41a885bce29f7a70f Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Tue, 28 Jan 2020 09:08:01 -0700 Subject: [PATCH 2/3] no message --- src/ManageTokens.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/ManageTokens.php b/src/ManageTokens.php index a6b5da1..77eb221 100644 --- a/src/ManageTokens.php +++ b/src/ManageTokens.php @@ -146,8 +146,6 @@ public static function register_jwt_fields_to( $type ) { /** * Given an array of fields, this returns an array with the new fields added - * - * @return array */ public static function add_user_mutation_input_fields() { $fields = [ @@ -164,8 +162,6 @@ public static function add_user_mutation_input_fields() { register_graphql_fields( 'RegisterUserInput', $fields ); register_graphql_fields( 'CreateUserInput', $fields ); register_graphql_fields( 'UpdateUserInput', $fields ); - - return $fields; } /** From 29071747293684924dee23ac2c9e63efdbadd7d4 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Tue, 28 Jan 2020 09:33:06 -0700 Subject: [PATCH 3/3] - Make the fields hookable per code review request --- src/ManageTokens.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ManageTokens.php b/src/ManageTokens.php index 77eb221..e69e52c 100644 --- a/src/ManageTokens.php +++ b/src/ManageTokens.php @@ -159,9 +159,19 @@ public static function add_user_mutation_input_fields() { ], ]; - register_graphql_fields( 'RegisterUserInput', $fields ); - register_graphql_fields( 'CreateUserInput', $fields ); - register_graphql_fields( 'UpdateUserInput', $fields ); + + $mutations_to_add_fields_to = apply_filters('graphql_jwt_auth_add_user_mutation_input_fields', [ + 'RegisterUserInput', + 'CreateUserInput', + 'UpdateUserInput', + ] ); + + if ( ! empty( $mutations_to_add_fields_to ) && is_array( $mutations_to_add_fields_to ) ) { + foreach ( $mutations_to_add_fields_to as $mutation ) { + register_graphql_fields( $mutation, $fields ); + } + } + } /**