Created
May 4, 2023 16:55
-
-
Save jasonbahl/0c85ed3de88c581fe19450f1f34dbb8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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