Query Batching with WPGraphQL

WPGraphQL allows clients to interact with WordPress via HTTP requests the /graphql API endpoint, or within the PHP context via execution of the graphql() function.

Many GraphQL Queries or Mutations can be executed in one API request or one page-load.

For example, if I were to use GraphQL to hydrate data for a shortcode I could have many shortcodes on my page and GraphQL would execute multiple times on that page.

Making many requests via the /graphql API endpoint is similar. An array of requests can be sent to the endpoint and an array of responses will be returned.

Screenshot showing a batch request from Postman

Screenshot showing multiple GraphQL queries in a single HTTP request, in the Postman API client

Smart GraphQL clients, such as Apollo Client, can take advantage of this feature to process multiple GraphQL requests in a single API call, making interactions with the server more efficient by reducing the number of round-trips needed.

If you use Apollo Client, you can read about configuring the batch HTTP link here.

You can read more about Query Batching here.