-
Notifications
You must be signed in to change notification settings - Fork 466
Description
Description
When writing a resolver for a connection and using the $connection->set_query_arg() method, the args are not properly being respected by the resolving class.
i.e. PostObjectConnectionResolver isn't properly consideration of any args set by set_query_arg().
Steps to reproduce
- register a custom connection:
add_action( 'graphql_register_types', function() {
register_graphql_connection( [
'fromType' => 'RootQuery',
'toType' => 'Post',
'fromFieldName' => 'curatedPosts',
'resolve' => function( $root, $args, $context, $info ) {
$resolver = new \WPGraphQL\Data\Connection\PostObjectConnectionResolver( $root, $args, $context, $info, 'any' );
// REPLACE WITH A LIST OF VALID POST IDS.
// ENOUGH TO PAGINATE AGAINST. IF NONE EXIST, GENERATE SOME.
// ALSO MAKE SURE THEY ARE NOT STRICTLY ORDERED NUMERICALLY FOR SANITY CHECKING (i.e. 1, 5, 3, 2 instead of 1,2,3,4,5)
$ids = [17, 105, 106, 15, 16, 18, 19, 30, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 29, 31];
return $resolver
->set_query_arg( 'post_status', 'any' )
->set_query_arg( 'post__in', $ids )
->set_query_arg( 'orderby', 'post__in' )
->get_connection();
}
] );
} );- Query for the posts:
{
curatedPosts(
first: 5
after:null
) {
nodes {
databaseId
}
pageInfo {
hasNextPage
endCursor
}
}
}- ✅ Verify that the first 5 posts match the first 5 in the
set_query_arg( 'post__in' )
$ids = [17, 105, 106, 15, 16, 18, 19, 30, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 29, 31];
first 5: = 17, 105, 106, 15, 16
looks good!
-
Use the
endCursorand query the next 5: -
👀 Expect to see the next 5 posts:
$ids = [17, 105, 106, 15, 16, 18, 19, 30, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 29, 31];
first 5: = 17, 105, 106, 15, 16
first 5, after 16 = 18, 19, 30, 20, 21
- 🙅🏻 🚫 Actually see that the response is NOT actually the next 5 items
- 😭
Additional context
This was brought to light by @AndrewKepson while using the WPGraphQL for ACF extension, where fields of the relationship type were not paginating as expected.
We were able to identify that it's not a general pagination bug, as using the { where: { in: [ ... ] } } arg on root connections paginates as expected.
It initially appeared to be a bug with WPGraphQL for ACF but we narrowed it down to a bug with WPGraphQL Connection Resolvers.
WPGraphQL Version
1.20.0
WordPress Version
7.4.2
PHP Version
8.2
Additional environment details
No response
Please confirm that you have searched existing issues in the repo.
- Yes
Please confirm that you have disabled ALL plugins except for WPGraphQL.
- Yes
- My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status


