hypertext, words and more

How to exceed more than 100 posts limit in WPGraphQL

Recently, I upgraded my site from Gatsby to Next.js. Personally, I wanted to see what kind of lift that would look like. It wasn’t too bad. My only problem with Gatsby so far has been how opinionated it all is. I spent way too much time configuring settings and plugins and fell into the weeds. I also didn’t love how the Gatsby-built GraphQL server queries looked different than the queries that happen on my actual site. I’ll write up a full post on that another time.

The line diff for a bare minimum conversion from Gatsby to Next.js with no type errors and a successful build was something like +1100/-1500 lines, not terrible. But expected since I had to find/replace Gatsby imports with Next imports, and I was able to nuke all the Gatsby plugins.

The single biggest problem I ran into was a dreadful non-error. Which was Next.js build was successful, but the maximum static posts it was generating was 100. What gives? Well apparently WPGraphQL limits queries to returning 100 posts out-of-the-box. To the authors: please document that somewhere.

I have over 300+ posts. So, I found that to be annoying. After much searching, according to this post on Spectrum Chat, you just plop this filter in your theme, and that should fix the issue:

function increase_query_limit($amount, $source, $args, $context, $info) {
  $amount = 1000; // whatever you want the limit to be, in this case 1000.
  return $amount;
}, 10, 5 );
add_filter('graphql_connection_max_query_amount', 'increase_query_limit');