graphql_post_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 postObjects, such as setting relationships, updating additional postmeta, or sending emails to Kevin. . . whatever you need to do with the postObject.
do_action( 'graphql_post_object_mutation_update_additional_data', int $post_id, array $input, WP_Post_Type $post_type_object, string $mutation_name, AppContext $context, ResolveInfo $info, string $default_post_status, string $intended_post_status );
Params
- $post_id (int): The ID of the postObject being mutated
- $input (array): The input for the mutation
- $post_type_object (WP_Post_Type): The Post Type object for the post being mutated
- $mutation_name (string): The name of the mutation (ex: create, update, delete)
- $context (AppContext): The AppContext passed down to all resolvers
- $info (ResolveInfo): The ResolveInfo passed down to all resolvers
- $default_post_status (string): The default status posts should use if an intended status wasn’t set
- $intended_post_status (string): The intended post_status the post should have according to the mutation input
Source
File: wp-graphql/src/Data/PostObjectMutation.php
Example
Extending mutation for post
add_action( 'graphql_post_object_mutation_update_additional_data', 'graphql_register_edit_mutation', 10, 5 );
function graphql_register_edit_mutation( $post_id, $input, $mutation_name, $context, $info ) {
// Consider other sanitization if necessary and validation such as which
// user role/capability should be able to insert this value, etc.
if ( ! empty( $input['example'] ) ) {
update_post_meta( $post_id, 'example', $input['example'] );
}
}