graphql_user_object_mutation_update_additional_data

Run an action after the additional data has been updated. This is a great spot to hook into to update additional data related to users, such as setting relationships, updating additional usermeta, or sending emails to Kevin… whatever you need to do with the userObject

do_action( 'graphql_user_object_mutation_update_additional_data', int $user_id, array $input, string $mutation_name, AppContext $context, ResolveInfo $info );

Params

  • $user_id (int): The ID of the user being mutated
  • $input (array): The input for the mutation
  • $mutation_name (string): The name of the mutation (ex: create, update, delete)
  • $context (AppContext): The AppContext passed down the Resolve tree
  • $info (ResolveInfo): The ResolveInfo passed down the Resolve tree

Source

File: wp-graphql/src/Data/UserMutation.php

Example

Extending mutation for user

/**
 * Run an action after the additional data has been updated. This is a great spot to hook into to
 * update additional data related to users, such as setting relationships, updating additional usermeta,
 * or sending emails to Kevin... whatever you need to do with the userObject.
 *
 * @param int $user_id The ID of the user being mutated
 * @param array $input The input for the mutation
 * @param string $mutation_name The name of the mutation (ex: create, update, delete)
 * @param AppContext $context The AppContext passed down the resolve tree
 * @param ResolveInfo $info The ResolveInfo passed down the Resolve Tree
 */

add_action( 'graphql_user_object_mutation_update_additional_data', 'graphql_register_user_mutation', 10, 5 );

function graphql_register_user_mutation( $user_id, $input, $mutation_name, $context, $info ) {
	if ( isset( $input['hobbies'] ) ) {
		// Consider other sanitization if necessary and validation such as which
		// user role/capability should be able to insert this value, etc.
		update_user_meta( $user_id, 'hobbies', $input['hobbies'] );
	}
}