graphql_connection_page_info

Filter the pageInfo that is returned to the connection.

This filter allows for additional fields to be filtered into the pageInfo of a connection, such as “totalCount”, etc, because the filter has enough context of the query, args, request, etc to be able to calcuate and return that information.

apply_filters( 'graphql_connection_page_info', array $page_info, AbstractConnectionResolver $resolver );

Params

  • $page_info (array): Array containing page info
  • $resolver (AbstractConnectionResolver): Instance of the connection resolver

Example

You would want to register a “total” field to the PageInfo type, then filter the pageInfo to return the total for the query, something to this tune:

add_filter( 'graphql_connection_page_info', function( $page_info, $connection ) {

  $page_info['total'] = null;

  if ( $connection->query instanceof WP_Query ) {
    if ( isset( $connection->query->found_posts ) {
      $page_info['total'] = (int) $connection->query->found_posts;
    }
  }

  return $page_info;

});