Skip to content

Instantly share code, notes, and snippets.

@jasonbahl
Created May 4, 2023 16:55
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/0c85ed3de88c581fe19450f1f34dbb8b to your computer and use it in GitHub Desktop.
Save jasonbahl/0c85ed3de88c581fe19450f1f34dbb8b to your computer and use it in GitHub Desktop.
add_action( 'graphql_return_response', function( $filtered_response, $response, $schema, $operation, $query, $variables, $request, $query_id ) {
$errors = [];
if ( ! is_array( $filtered_response ) && ! empty( $filtered_response->errors ) && is_array( $filtered_response->errors ) ) {
$errors = $filtered_response->errors;
} else if ( is_array( $filtered_response ) && ! empty( $filtered_response['errors'] ) && is_array( $filtered_response['errors'] ) ) {
$errors = $filtered_response['errors'];
}
if ( empty( $errors ) ) {
return;
}
array_map( function( $error ) use ( $query, $variables ) {
if ( ! empty( $message = $error->getMessage() ) ) {
error_log( 'graphql_error: ' . $message . ', query: ' . wp_json_encode( $query ) . 'variables: ' . wp_json_encode( $variables ) );
}
}, $errors );
}, 10, 8 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment