Archives: Actions

  • graphql_init

    Fires after themes have been setup, allowing for both plugins and themes to register things before graphql_init

    do_action( 'graphql_init', WPGraphQL $instance );

    Params

    • $instance (WPGraphQL): The instance of the WPGraphQL class

    Source

    File: wp-graphql/wp-graphql.php

  • graphql_get_type_registry

    Fire an action when the Type Register is returned

    do_action( 'graphql_get_type_registry', WPGraphQL\Registry\TypeRegistry $type_registry );

    Params

    • $type_registry (WPGraphQL\Registry\TypeRegistry): The registry of Types used in the GraphQL Schema

    Source

    File: wp-graphql/wp-graphql.php

  • graphql_get_schema

    Fire an action when the Schema is returned

    do_action( 'graphql_get_schema', WPGraphQL\WPSchema $schema );

    Params

    • $schema (WPGraphqL\WPSchema): The Schema definition

    Source

    File: wp-graphql/wp-graphql.php

  • graphql_register_initial_types

    Fire an action as the type registry is initialized. This executes before the graphql_register_types action to allow for earlier hooking

    do_action( 'graphql_register_initial_types', WPGraphQL\Registry\TypeRegistry $type_registry );

    Params

    • $type_registry (WPGraphQL\Registry\TypeRegistry): The registry of Types used in the GraphQL Schema

    Source

    File: wp-graphql/src/Registry/TypeRegistry.php

  • graphql_get_debug_log

    Fires when the debug logs are retrieved

    do_action( 'graphql_get_debug_log', WPGraphQL\Utils\DebugLog $debug_log );

    Params

    • $debug_log (WPGraphQL\Utils\DebugLog): An instance of the DebugLog class

    Source

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

    Example

    add_action( 'graphql_get_debug_log', function( \WPGraphQL\Utils\DebugLog $debug_log ) use ( $message, $config ) {
    	return $debug_log->add_log_entry( $message, $config );
    } );
  • graphql_wp_union_type

    Run an action when the WPObjectType is instantiating

    do_action( 'graphql_wp_union_type', array $config, WPGraphQL\Type\WPUnionType $union_type );

    Params

    • $config (array): Array of configuration options passed to the WPUnionType when instantiating a new type
    • $union_type (WPGraphQL\Type\WPUnionType): The instance of the WPUnionType class

    Source

    File: wp-graphql/src/Type/WPUnionType.php

  • graphql_wp_object_type

    Run an action when the WPObjectType is instantiating

    do_action( 'graphql_wp_object_type', array $config, WPGraphQL\Type\WPObjectType $object_type );

    Params

    • $config (array): Array of configuration options passed to the WPObjectType when instantiating a new type
    • $object_type (WPGraphQL\Type\WPObjectType): The instance of the WPObjectType class

    Source

    File: wp-graphql/src/Type/WPObjectType.php

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

    Fire an action as the type registry is initialized. This executes during the graphql_register_types action to allow for earlier hooking

    do_action( 'graphql_register_types_late', WPGraphQL\Registry\TypeRegistry $type_registry );

    Params

    • $type_registry (WPGraphQL\Registry\TypeRegistry): The registry of Types used in the GraphQL Schema

    Source

    File: wp-graphql/src/Registry/TypeRegistry.php

  • init_graphql_type_registry

    Fires an action as the Type registry is being initiated

    do_action( 'init_graphql_type_registry', WPGraphQL\Registry\TypeRegistry $type_registry );

    Params

    • $type_registry (WPGraphQL\Registry\TypeRegistry): The registry of Types used in the GraphQL Schema

    Source

    File: wp-graphql/src/Registry/TypeRegistry.php