Skip to content

Commit e0152a9

Browse files
authored
Merge pull request #66 from jasonbahl/bug/wpgraphql-v0.6.0-regression
- WPGraphQL v0.6.0 regression
2 parents 2ebbc31 + 2907174 commit e0152a9

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/ManageTokens.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
namespace WPGraphQL\JWT_Authentication;
1010

1111
use GraphQL\Error\UserError;
12-
use GraphQL\Type\Definition\Type;
13-
use WPGraphQL\Model\User;
14-
use WPGraphQL\Types;
1512

1613
/**
1714
* Class - ManageToken
@@ -25,7 +22,7 @@ public static function init() {
2522
add_action( 'graphql_register_types', [ __CLASS__, 'add_jwt_fields' ], 10 );
2623

2724
// Add fields to the input for user mutations.
28-
add_filter( 'graphql_user_mutation_input_fields', [ __CLASS__, 'add_user_mutation_input_fields' ] );
25+
add_action( 'graphql_register_types', [ __CLASS__, 'add_user_mutation_input_fields' ] );
2926
add_action( 'graphql_user_object_mutation_update_additional_data', [ __CLASS__, 'update_jwt_fields_during_mutation' ], 10, 3 );
3027

3128
// Filter the signed token, preventing it from returning if the user has had their JWT Secret revoked.
@@ -149,22 +146,32 @@ public static function register_jwt_fields_to( $type ) {
149146

150147
/**
151148
* Given an array of fields, this returns an array with the new fields added
152-
*
153-
* @param array $fields The input fields for user mutations.
154-
*
155-
* @return array
156149
*/
157-
public static function add_user_mutation_input_fields( array $fields ) {
158-
$fields['revokeJwtUserSecret'] = [
159-
'type' => Types::boolean(),
160-
'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' ),
161-
];
162-
$fields['refreshJwtUserSecret'] = [
163-
'type' => Types::boolean(),
164-
'description' => __( 'If true, this will refresh the users JWT secret.' ),
150+
public static function add_user_mutation_input_fields() {
151+
$fields = [
152+
'revokeJwtUserSecret' => [
153+
'type' => 'Boolean',
154+
'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' ),
155+
],
156+
'refreshJwtUserSecret' => [
157+
'type' => 'Boolean',
158+
'description' => __( 'If true, this will refresh the users JWT secret.' ),
159+
],
165160
];
166161

167-
return $fields;
162+
163+
$mutations_to_add_fields_to = apply_filters('graphql_jwt_auth_add_user_mutation_input_fields', [
164+
'RegisterUserInput',
165+
'CreateUserInput',
166+
'UpdateUserInput',
167+
] );
168+
169+
if ( ! empty( $mutations_to_add_fields_to ) && is_array( $mutations_to_add_fields_to ) ) {
170+
foreach ( $mutations_to_add_fields_to as $mutation ) {
171+
register_graphql_fields( $mutation, $fields );
172+
}
173+
}
174+
168175
}
169176

170177
/**

0 commit comments

Comments
 (0)