How to increase the WPGraphQL query limit

December 15th, 2021

WPGraphQL is a wonderful plugin that enables GraphQL querying of WordPress content, but unfortunately it limits the amount of posts you can query at a time to 100 by default.

In this post, we are going to show you the best way to increase this limit.

The main solution originally presented by Jason Bahl (the creator of WPGraphQL) is to paste this function into the bottom of your WordPress theme's functions.php file:

add_filter( 'graphql_connection_max_query_amount', function( $amount, $source, $args, $context, $info ) {
if(current_user_can( 'manage_options')) {
$amount = 1000; // increase post limit to 1000
return $amount;
}, 10, 5 );
// not the ideal solution. For best solution, see below.

However, an issue that users have noticed with this solution is that although it works inside of the GraphiQL plugin (inside of the WordPress instance), the 100 post limit often remains for outside services querying for your WordPress content (such as Vercel, Netlify, or Heroku).

The problem is with the statement: if(current_user_can( 'manage_options'). Outside queries will not satisfy this condition, so the new $amount will not be set.

So the best solution is to remove the if statement and just set the $amount directly no matter what:

// best solution
add_filter( 'graphql_connection_max_query_amount', function( $amount, $source, $args, $context, $info ) {
$amount = 1000; // increase post limit to 1000
return $amount;
}, 10, 5 );

Disclaimer: fetching too many things in one request can cause slowdowns for the client and possibly server performance issues as well. There's no magic number to what the right amount of posts to return for optimal performance, but the more data the server is processing and the more the client is downloading, the worse the performance tends to be. Sometimes you can get better performance from more, but smaller, requests.

Additional Notes

Make sure you paste the function above into the bottom of your wp-content/themes/[theme_name]/functions.php file.

If you have multiple themes and aren't sure which theme you're currently using, you can go to Appearance --> Themes and it will show you the currently active theme.

If you're looking for a good plugin for surfing your WordPress folders and files (and making edits to them), I recommend WP File Manager.

And that's it! Thanks for reading, and I hope this article was helpful to you.

If you liked this post, consider following me on twitter and/or subscribing to the blog using the form below.

Recommended Posts

HubSpot Forms in React: Submit a form using the HubSpot API

In this post you will learn how to submit HubSpot forms from your React website using the HubSpot API.

Read more

React: Recreating the Hacker News comments section

In this post we'll use React to recreate the Hacker News comment section using a recursively generated comment tree.

Read more