Skip to content

Instantly share code, notes, and snippets.

@jasonbahl
Created August 18, 2022 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonbahl/e63f5c1c84df65868077cb666fcbc2a1 to your computer and use it in GitHub Desktop.
Save jasonbahl/e63f5c1c84df65868077cb666fcbc2a1 to your computer and use it in GitHub Desktop.
add_action( 'wpgraphql_cache_purge_nodes', function( $key = 'purge', $nodes = [] ) {
$pipedream_debugging = function_exists( 'get_graphql_setting' ) ? \get_graphql_setting( 'pipedream_post', 'off', 'purge_debugging' ) : 'off';
$enabled = $pipedream_debugging === 'on';
if ( ! $enabled || empty( $nodes ) ) {
return;
}
$args = [
'headers' => [
'Content-Type' => 'application/json',
],
'body' => wp_json_encode([
'endpoint' => site_url( \WPGraphQL\Router::$route ),
'key' => $key,
'nodes' => $nodes,
]),
'method' => 'POST',
'data_format' => 'body',
'blocking' => false,
];
wp_safe_remote_post( 'https://eop5fazakbebfeh.m.pipedream.net', $args );
}, 10, 2 );
add_action( 'graphql_register_settings', function() {
register_graphql_settings_section( 'purge_debugging', [
'title' => 'Purge Debugging',
'desc' => 'Debugging purge events'
]);
register_graphql_settings_field( 'purge_debugging', [
'name' => 'pipedream_post',
'label' => 'Enable Pipedream Payloads',
'desc' => 'Enable payloads to be sent to Pipedream for monitoring',
'type' => 'checkbox',
'default' => 'off'
] );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment