Archives: Actions

  • graphql_return_response

    Run an action after the response has been filtered, as the response is being returned. This is a good place for debug tools to hook in to log things, etc.

    do_action( 'graphql_return_response', array $filtered_response, array $response, WPGraphQL\WPSchema $schema, string $operation, string $query, array $variables, Request $request );

    Params

    • $filtered_response (array): The filtered response for the GraphQL request
    • $response (array): The response for your GraphQL request
    • $schema (WPGraphQL\WPSchema): The schema object for the root request
    • $operation (string): The name of the operation
    • $query (string): The query that GraphQL executed
    • $variables (array|null): Variables passed to your GraphQL query
    • $request (Request): Instance of the Request object

    Source

    File: wp-graphql/src/Request.php

  • graphql_execute

    Run an action. This is a good place for debug tools to hook in to log things, etc.

    do_action( 'graphql_execute', array $response, WPGraphQL\WPSchema $schema, string $operation, string $query, array $variables, Request $request );

    Params

    • $response (array): The response for your GraphQL request
    • $schema (WPGraphQL\WPSchema): The schema object for the root request
    • $operation (string): The name of the operation
    • $query (string): The query that GraphQL executed
    • $variables (array|null): Variables passed to your GraphQL query
    • $request (Request): Instance of the Request object

    Source

    File: wp-graphql/src/Request.php

  • init_graphql_request

    Action that executes when a GraphQL Request begins. This is a great place for plugins to hook in and modify things that should only occur in the context of a GraphQL Request. The base class hooks into this action to kick off the schema creation, types are not set up until this action has run.

    do_action( 'init_graphql_request' );

    Source

    File: wp-graphql/src/Request.php

  • graphql_insert_post_object

    Fires after a single term is created or updated via a GraphQL mutation

    do_action( 'graphql_insert_post_object', int $post_id, WP_Post_Type $post_type_object, array $post_args, string $mutation_name );

    Params

    • $post_id (int): Inserted post ID
    • $post_type_object (WP_Post_Type): The Post Type object for the post being mutated
    • $args (array): The args used to insert the term
    • $mutation_name (string): The name of the mutation being performed

    Source

    File: wp-graphql/src/Mutation/PostObjectUpdate.php

  • graphql_post_object_mutation_set_object_terms

    Fire an action before setting object terms during a GraphQL Post Object Mutation. One example use for this hook would be to create terms from the input that may not exist yet, so that they can be set as a relation below.

    do_action( 'graphql_post_object_mutation_set_object_terms', int $post_id, array $input, WP_Post_Type $post_type_object, string $mutation_name );

    Params

    • $post_id (int): Inserted post ID
    • $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 being performed

    Source

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

  • 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'] );
    	}
    }
  • graphql_after_return_field_from_model

    Hook that fires after the data is returned for the field

    do_action( 'graphql_after_return_field_from_model', string $result, string $key, string $model_name, mixed $data, string $visibility, int $owner, WP_User $current_user );

    Params

    • $results (string): The returned data for the field
    • $key (string): The name of the field on the type
    • $model_name (string): Name of the model the filter is currently being executed in
    • $data (mixed): The un-modeled incoming data
    • $visibility (string): The visibility setting for this piece of data
    • $owner (null|int): The user ID for the owner of this piece of data
    • $current_user (WP_User): The current user for the session

    Source

    File: wp-graphql/src/Model/Model.php

  • graphql_media_item_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 mediaItems, such as updating additional postmeta, or sending emails to Kevin. . .whatever you need to do with the mediaItem.

    do_action( 'graphql_media_item_mutation_update_additional_data', int $media_item_id, array $input, WP_Post_Type $post_type_object, string $mutation_name, AppContext $context, ResolveInfo $info );

    Params

    • $media_item_id (int): The ID of the mediaItem being mutated
    • $input (array): The input for the mutation
    • $post_type_object (WP_Post_Type): The Post Type Object for the type of post being mutated
    • $mutation_name (string): The name of the mutation (ex: create, update, delete)
    • $context (AppContext): The AppContext that is passed down the resolve tree
    • $info (ResolveInfo): The ResolveInfo that is passed down the resolve tree

    Source

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

  • graphql_after_resolve_field

    Fire an action AFTER the field resolves

    do_action( 'graphql_after_resolve_field', mixed $source, array $args, AppContext $context, ResolveInfo $info, mixed $field_resolver, string $type_name, string $field_key, FieldDefinition $field, mixed $result );

    Params

    • $source (mixed): The source passed down the Resolve Tree
    • $args (array): The args for the field
    • $context (AppContext): The AppContext that is passed down the resolve tree
    • $info (ResolveInfo): The ResolveInfo that is passed down the resolve tree
    • $field_resolver (mixed): The field resolver function
    • $type_name (string): The name of the type the fields belong to
    • $field_key (string): The name of the field
    • $field (FieldDefinition): The Field Definition for the resolving field
    • $result (mixed): The result of the field resolver

    Source

    File: wp-graphql/src/Utils/InstrumentSchema.php

  • graphql_before_resolve_field

    Fire an action BEFORE the field resolves

    do_action( 'graphql_before_resolve_field', mixed $source, array $args, AppContext $context, ResolveInfo $info, mixed $field_resolver, string $type_name, string $field_key, FieldDefinition $field );

    Params

    • $source (mixed): The source passed down the Resolve Tree
    • $args (array): The args for the field
    • $context (AppContext): The AppContext that is passed down the resolve tree
    • $info (ResolveInfo): The ResolveInfo that is passed down the resolve tree
    • $field_resolver (mixed): The field resolver function
    • $type_name (string): The name of the type the fields belong to
    • $field_key (string): The name of the field
    • $field (FieldDefinition): The Field Definition for the resolving field

    Source

    File: wp-graphql/src/Utils/InstrumentSchema.php