When acquiring the WP_Query instance inside of wp-graphql filters, it causes post hooks such as posts_pre_query to fire a second time within the wp-graphql request lifecyle.
Digging into WordPress core we can see the side-effect of instantiating a new instance of WP_Query calls $this->query( $query ) in its constructor and then calls $this->get_posts()
Description
When acquiring the WP_Query instance inside of wp-graphql filters, it causes post hooks such as
posts_pre_query
to fire a second time within the wp-graphql request lifecyle.Example
Explanation
In the case the
AbstractConnectionResolver
is an instance ofPostObjectConnectionResolver
we can see that theWP_Query
class is instantiatedhttps://github.com/wp-graphql/wp-graphql/blob/9ee971695cdb848d7b51afdd2df837bdf111df76/src/Data/Connection/PostObjectConnectionResolver.php#L94-L107
Digging into WordPress core we can see the side-effect of instantiating a new instance of
WP_Query
calls$this->query( $query )
in its constructor and then calls$this->get_posts()
https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-query.php#L3787
This results in applying the
posts_pre_query
and other hooks https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-query.php#L3136Steps to reproduce
Define hooks:
With wp-graphql debug enabled run the query
Additional context
No response
WPGraphQL Version
1.13.8
WordPress Version
6.1.1
PHP Version
7.4 & 8
Additional enviornment details
Observed in wp-graphql-offset-pagination https://github.com/valu-digital/wp-graphql-offset-pagination/blob/master/src/Loader.php#L128
Please confirm that you have searched existing issues in the repo.
Please confirm that you have disabled ALL plugins except for WPGraphQL.