This hook receives the following parameters (in this same order):
#
Mandatory?
Param
Description
1
✅
$query
The GraphQL query to execute
2
❌
$variables
GraphQL variables
3
❌
$operationName
The operation name to execute
4
❌
$executeAsUser
The user to log-in to execute the query
5
❌
$schemaConfigurationIDOrSlug
The schema configuration ID (as an int) or slug (as a string) to apply when executing the query. Passing null will use the default value, and passing -1 means "use no schema configuration"
The $executeAsUser parameter is needed if the query requires the user to be logged-in, such as when executing a mutation:
If provided, the user with given ID (as an int) or username (as a string) will be logged-in right before executing the GraphQL query, and logged-out immediately afterwards.
If not provided, no user will be logged-in when executing the query.
The following WP-Cron event executes hook gatographql__execute_persisted_query to send a daily email indicating the number of new comments added to the site:
In the last 24 hs
In the last 1 year
Since the beginning of the month
Since the beginning of the year
We create a Persisted Query with slug "daily-stats-by-email-number-of-comments" and content:
Then, we schedule the WP-Cron event, either via PHP: