feat(logging): Refactor query event lifecycle for modularity. Added more lifecycle options. #394
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request refactors the WPGraphQL logging system to improve modularity and maintainability by addressing the "god class" anti-pattern. The primary changes involve splitting the monolithic
QueryEventLifecycleclass into smaller, more focused components.Key changes include:
QueryEventLifecyclenow serves as a Facade.QueryActionLoggerandQueryFilterLoggerclasses are now responsible for handling all logging events related to WordPress actions and filters, respectively.LoggingHelpertrait centralizes theis_logging_enabled()logic.Related Issue
Fixes #390
Dependant PRs
N/A
Type of Change
How Has This Been Tested?
The following manual tests were performed to verify the functionality of each new logging point.
Testing Environment
Manual Testing Instructions
Action Hook Tests
Events::PRE_REQUEST)Events::BEFORE_GRAPHQL_EXECUTION)Events::BEFORE_RESPONSE_RETURNED)Filter Hook Tests
Events::REQUEST_DATA)Events::REQUEST_RESULTS)Events::RESPONSE_HEADERS_TO_SEND)X-WPGraphQL-Logging-IDwith a unique ID.Global Filter Test
wpgraphql_logging_is_enabled)functions.php:add_filter('wpgraphql_logging_is_enabled', function($is_enabled, $config) {$query_name = $config['query_name'] ?? '';
if ($query_name === 'GetPost') {
return false;
}
return $is_enabled;
}, 10, 2);
Then, run a query named
GetPostand another query namedGetPosts.GetPostquery should not log, whileGetPostsquery should log normally.Screenshots
Checklist