fix: set_query_arg not properly respected by connection resolvers#3037
fix: set_query_arg not properly respected by connection resolvers#3037jasonbahl wants to merge 2 commits intowp-graphql:developfrom
Conversation
- set internal $query_args variable to be PostObjectConnectionResolver->query_args instead of empty array (respect what's been set by set_query_arg())
|
this is breaking a lot of tests, so I converted to a draft. It fixes the problem at hand from what I can tell, but clearly not the "right" solution overall yet. |
|
Code Climate has analyzed commit 5dd69d2 and detected 0 issues on this pull request. View more on Code Climate. |
I'm not by my desk, but iirc this was part of the impetus for #2749 and might even be working there already. If so we can isolate and cherrypick in a way that isn't b/c. |
|
closing this as I believe there's a way to resolve this without making changes to core WPGraphQL (at least not immediately). Instead of: $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();We can do the following: // override the args that are passed in, as if a user passed them in.
$args['where']['in'] = [17, 105, 106, 15, 16, 18, 19, 30, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 29, 31];
$resolver = new \WPGraphQL\Data\Connection\PostObjectConnectionResolver( $root, $args, $context, $info, 'page' );This will let the internals of the Connection Resolvers do things as if a user were passing in the args. |
|
closing this as I was able to accomplish what was needed by adjusting the Basically, for better or worse, the *ConnectionResolver classes use the Then For arguments like see: https://github.com/wp-graphql/wpgraphql-acf/pull/167/files |
What does this implement/fix? Explain your changes.
This addresses a bug where args set by
$connection->set_query_arg()weren't being properly respected by the Connection Resolver class.The instantiation of the query_args was happening at init, and so set_query_arg was happening too late.
By moving the instantiation to the
execute_and_get_ids, this ensures thatset_query_arg()has been properly applied between initializing and executing.Does this close any currently open issues?
closes #3036