Skip to content

Instantly share code, notes, and snippets.

@jasonbahl
Created July 5, 2019 17:25
Show Gist options
  • Save jasonbahl/d2dfe0c56390e9c9c8b0c25d7d6c4bd2 to your computer and use it in GitHub Desktop.
Save jasonbahl/d2dfe0c56390e9c9c8b0c25d7d6c4bd2 to your computer and use it in GitHub Desktop.
add_filter( 'graphql_post_object_connection_query_args', function( $args ) {
$args['no_found_rows'] = false;
return $args;
} );
add_filter( 'graphql_connection_page_info', function( $page_info, $connection ) {
$page_info['total'] = null;
if ( $connection->get_query() instanceof \WP_Query ) {
if ( isset( $connection->get_query()->found_posts ) ) {
$page_info['total'] = (int) $connection->get_query()->found_posts;
}
}
return $page_info;
}, 10, 2 );
add_action( 'graphql_register_types', function() {
register_graphql_field( 'WPPageInfo', 'total', [
'type' => 'Int',
] );
});
@mashhoodr
Copy link

Where do we need to add this script? Thanks!

@ivanjeremic
Copy link

Should we use wp-graphql-offset-pagination Plugin over this?

@kumaranup594
Copy link

kumaranup594 commented May 30, 2020

I was also looking for this solution and added into a simple plugin - you can use it
wp-graphql-nexgi-extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment