fix: Move graphql_root_value filter execution to runtime for access to request params #3406
+119
−273
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.
What does this implement/fix? Explain your changes.
🐛 Problem:
The
graphql_root_valuefilter was being applied during the Request constructor before request parameters were parsed, preventing developers from accessing valuable request context (query string, variables, operation name, etc.) when filtering the root value.Current behavior:
Impact:
✅ Solution
Move root value determination to execution time when request parameters are available:
$this->root_value = $this->get_root_value();🧪 Testing
Added comprehensive test coverage in FiltersTest.php:
testFilterGraphqlRootValueHasAccessToRequestParams()testFilterGraphqlRootValueHasAccessToRequestParamsForBatchQuery()Does this close any currently open issues?
closes #3405
Any other comments?
This supports a use-case in WPGraphQL Subscriptions:
⚡ Backward Compatibility
This change should be fully backward compatible. Existing
graphql_root_valuefilter callbacks that don't use request context will continue to work exactly as before. The change only adds new capabilities for filters that want to access request information, which was previously null so no filters would have been using it.