graphql_connection_max_query_amount

Filter the maximum number of posts per page that should be queried. The default is 100 to prevent queries from being exceedingly resource intensive, however individual systems can override this for their specific needs. This filter is intentionally applied AFTER the query_args filter.

apply_filters( 'graphql_connection_max_query_amount', Int $max_amount, mixed $source, array $args, AppContext $context, ResolveInfo $info );

Params

  • $max_amount (int): Maximum number of items to return for the connection. Too high of a number can cause performance bottlenecks on the server. It’s recommended to keep this lower and encourage clients to paginate requests to get more items.
  • $source (mixed): Source passed down from the resolve tree
  • $args (array): Array of arguments input in the field as part of the GraphQL query
  • $context (AppContext): Object containing app context that gets passed down the resolve tree
  • $info (ResolveInfo): Info about fields passed down the resolve tree

Examples

Filter the max query amount for a specific connection based on field name

This example shows how to filter the max query amount for a specific field name in the Schema. In this case, it filters the connection from the field named productCategories to have a max amount of 150, instead of the default 100.

/*
 * Increase perPage for product categories. This is needed to build out the sidebar accordion.
 */
add_filter( 'graphql_connection_max_query_amount', function ( int $max_amount, $source, array $args, $context, $info ) {
	// Bail if the fieldName isn't avail
	if ( empty( $info->fieldName ) ) {
		return $max_amount;
	}
	// Bail if we're not dealing with our target fieldName
	if ( 'productCategories' !== $info->fieldName ) {
		return $max_amount;
	}
	return 150;
}, 10, 5 );