-
Notifications
You must be signed in to change notification settings - Fork 466
Closed
Labels
component: connectionsRelating to GraphQL ConnectionsRelating to GraphQL Connectionscomponent: paginationRelating to paginationRelating to paginationcomponent: queryRelating to GraphQL QueriesRelating to GraphQL Queriesstatus: actionableReady for work to beginReady for work to begintype: enhancementImprovements to existing functionalityImprovements to existing functionality
Description
What problem does this address?
Hi.
I have a situation where we are using paginated queries, but need to apply complex access control logic.
This section from PostObjectConnectionResolver illustrates the issue:
/**
* {@inheritDoc}
*/
public function get_ids_from_query()
{
$ids = !empty($this->query->posts) ? $this->query->posts : [];
// FIXME: this is where we should filter entries according to security rules
foreach($ids as $id) {
}
// If we're going backwards, we need to reverse the array.
if (!empty($this->args['last'])) {
$ids = array_reverse($ids);
}
return $ids;
}
Existing filters let us either filter the WP_Query upstream (but our logic can't be expressed as a meta query), or the returned ids after cursors have been applied to them.
Currently, the AbstractConnectionResolver applies cursors immediately to the output of the above function.
What is your proposed solution?
A filter after ids have been retrieved, but before cursors are applied to them.
What alternatives have you considered?
I have tried to override the PostObjectConnectionResolver:
register_graphql_connection(
[
'fromType' => 'RootQuery',
'toType' => ucfirst($post_type->graphql_single_name),
'queryClass' => 'WP_Query',
'fromFieldName' => $post_type->graphql_plural_name,
'connectionArgs' => PostObjects::get_connection_args(),
'resolve' => function ($root, $args, $context, $info) use ($post_type) {
$resolver = new \WPGraphQL\Data\Connection\CustomPostObjectConnectionResolver($root, $args, $context, $info, $post_type);
return $resolver->get_connection();
},
]
);
In:
graphql_register_types
But obviously, this results in a complaint about duplicate types.
Is something like this possible currently?
Additional Context
No response
Metadata
Metadata
Assignees
Labels
component: connectionsRelating to GraphQL ConnectionsRelating to GraphQL Connectionscomponent: paginationRelating to paginationRelating to paginationcomponent: queryRelating to GraphQL QueriesRelating to GraphQL Queriesstatus: actionableReady for work to beginReady for work to begintype: enhancementImprovements to existing functionalityImprovements to existing functionality
Type
Projects
Status
✅ Done