GraphQL Query Batching
Stellate supports GraphQL Query Batching out of the box without any special configuration or support from your backend services required.
While a usual GraphQL JSON payload looks like this:
{
"query": "{ roadster { name } }"
}
With query batching you can instead send multiple queries via a single request like this:
[
{ "query": "{ roadster { name } }" },
{ "query": "{ launchesPast(limit: 5) { mission_name, launch_date_utc } }" }
]
When Stellate receives a set of batched queries, they get analyzed at the edge locations, split into individual requests, and then handled concurrently by either the cache itself (if results for that query have already been cached) or sent back to the GraphQL backend servers configured for that service.
Stellate will then wait until all requests have been answered, merge the individual responses, and send them back to the client.
There is no special configuration needed to enable support for Query Batching and any cache rules and scopes that you have configured for your service will apply to the individual queries included in a batch as well.
If you want to give this a try and don't have a service at hand, feel free to use our SpaceX GraphQL API instance. To run a batched query, take a look at the examples below (or feel free to come up with your own and run it against the above service)
# Batched query asking for information on the space roadster as well
# as the last 3 SpaceX launches
curl --location --request POST 'https://spacex-api.stellate.sh/' --header 'Content-Type: application/json' --data-raw '[ { "query": "{ roadster { name details wikipedia norad_id speed_kph earth_distance_km mars_distance_km } }" }, { "query": "{ launchesPast(limit: 5) { mission_name launch_date_utc launch_site { site_name_long } links { article_link video_link } } }" } ]'
The (nicely formatted) query itself looks like this:
[
{
"query": "{
roadster {
name
details
wikipedia
norad_id
speed_kph
earth_distance_km
mars_distance_km
}
}"
},
{
"query": "{
launchesPast(limit: 5) {
mission_name
launch_date_utc
launch_site {
site_id
site_name
site_name_long
}
links {
article_link video_link
}
}
}"
}
]
If you have any questions or are running into issues with batched queries, please let us know at support@stellate.co or via the chat button on this page.