How can multiple queries be batched into a single request to GitHub's GraphQL API?
For example, how would you batch these 2 queries into a single request and receive a single response? And would this technique work with many more queries (say 200)?
{
repositoryOwner(login:"rails") {
repository(name:"rails") {
description
homepageURL
}
}
}
{
repositoryOwner(login:"github") {
repository(name:"graphql-client") {
description
homepageURL
}
}
}
(The GitHub GraphQL API can be experimented with at https://developer.github.com/early-access/graphql/explorer/)
You need to wrap the calls to both fields in one query:
{
repositoryOwner(login:"rails") {
repository(name:"rails") {
description
homepageURL
}
}
repositoryOwner(login:"github") {
repository(name:"graphql-client") {
description
homepageURL
}
}
}
This will still fail though, as there are now two fields in the output with the same name (repositoryOwner), so you need to alias them:
{
rails: repositoryOwner(login:"rails") {
repository(name:"rails") {
description
homepageURL
}
}
graphql_client: repositoryOwner(login:"github") {
repository(name:"graphql-client") {
description
homepageURL
}
}
}
See this explanation.
If you could generate a unique alias for every one of your queries, then yes this technique should work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With