Make multiple GraphQL queries in a single request
Optimize your dashboard load times.
When building a dashboard, you often need to fetch data from multiple sources. A typical dashboard might require 10-15 different queries. Making each query as a separate request is inefficient because:
- Each request requires a full network round trip
- Sequential requests increase the total loading time
- Multiple requests create unnecessary overhead
GraphQL solves this by allowing you to combine multiple queries into a single request. This approach:
- Reduces network overhead by making one request instead of many
- Improves performance through parallel query execution
- Provides a better user experience with faster load times
When Propel receives a request with multiple queries, it automatically parallelizes them to return the data as quickly as possible.
Example dataset
In the following example, we’ll use the same data that we used in our Quickstart.
It contains sales data from taco restaurants, and it has the following structure, shown in the table below:
Combine multiple queries into one request
Suppose you want to show three charts on your dashboard:
- Total taco sales in dollars plotted over time
- The number of taco sales plotted over time
- Top-performing restaurants with the most revenue
Instead of sending three separate requests for these charts, you can combine them into one:
Let’s break down the key aspects of this example:
-
Single request efficiency: Instead of making three separate API calls, we combined all queries into one GraphQL request. This reduces network overhead and improves performance.
-
Query naming: Each time series query has a unique name (
revenue
andorderCount
) to prevent naming conflicts. This makes it easy to identify and access specific data in the response. -
Response structure: The JSON response organizes results by query name:
revenue
: Contains revenue data over timeorderCount
: Contains order count data over timeleaderboard
: Contains the top restaurants by revenue
Ready to experiment? Try running these queries in the API Playground. You can modify the queries and see the results in real-time.
Was this page helpful?