<labelid="sidebar-toggle"class="icon-button"for="sidebar-toggle-anchor"title="Toggle Table of Contents"aria-label="Toggle Table of Contents"aria-controls="sidebar">
<ahref="../print.html"title="Print this book"aria-label="Print this book">
<iid="print-button"class="fa fa-print"></i>
</a>
</div>
</div>
<divid="search-wrapper"class="hidden">
<formid="searchbar-outer"class="searchbar-outer">
<inputtype="search"id="searchbar"name="searchbar"placeholder="Search this book ..."aria-controls="searchresults-outer"aria-describedby="searchresults-header">
<p>The <ahref="https://graphql.org">GraphQL</a> standard generally assumes that there will be one server request per each client operation to perform (such as a query or mutation). This is conceptually simple but potentially inefficient.</p>
<p>Some client libraries (such as <ahref="https://www.apollographql.com/docs/link/links/batch-http.html"><code>apollo-link-batch-http</code></a>) have the ability to batch operations in a single <ahref="https://en.wikipedia.org/wiki/HTTP">HTTP</a> request to save network round-trips and potentially increase performance. There are <ahref="https://www.apollographql.com/blog/batching-client-graphql-queries#what-are-the-tradeoffs-with-batching">some tradeoffs</a>, though, that should be considered before <ahref="https://www.apollographql.com/blog/batching-client-graphql-queries">batching operations</a>.</p>
<p><ahref="https://docs.rs/juniper">Juniper</a>'s <ahref="index.html#officially-supported">server integration crates</a> support <ahref="https://www.apollographql.com/blog/batching-client-graphql-queries">batching multiple operations</a> in a single <ahref="https://en.wikipedia.org/wiki/HTTP">HTTP</a> request out-of-the-box via <ahref="https://www.json.org">JSON</a> arrays. This makes them compatible with client libraries that support <ahref="https://www.apollographql.com/blog/batching-client-graphql-queries">batch operations</a> without any special configuration.</p>
<blockquote>
<p><strong>NOTE</strong>: If you use a custom server integration, it's <strong>not a hard requirement</strong> to support <ahref="https://www.apollographql.com/blog/batching-client-graphql-queries">batching</a>, as it's not a part of the <ahref="https://spec.graphql.org/October2021">official GraphQL specification</a>.</p>
</blockquote>
<p>Assuming an integration supports <ahref="https://www.apollographql.com/blog/batching-client-graphql-queries">operations batching</a>, for the following GraphQL query:</p>
<pre><codeclass="language-graphql">{
hero {
name
}
}
</code></pre>
<p>The <ahref="https://www.json.org">JSON</a><code>data</code> to <ahref="https://en.wikipedia.org/wiki/POST_(HTTP)">POST</a> for an individual request would be:</p>
<pre><codeclass="language-json">{
"query": "{hero{name}}"
}
</code></pre>
<p>And the response would be in the form:</p>
<pre><codeclass="language-json">{
"data": {
"hero": {
"name": "R2-D2"
}
}
}
</code></pre>
<p>However, if we want to run the same query twice in a single <ahref="https://en.wikipedia.org/wiki/HTTP">HTTP</a> request, the batched <ahref="https://www.json.org">JSON</a><code>data</code> to <ahref="https://en.wikipedia.org/wiki/POST_(HTTP)">POST</a> would be:</p>
<pre><codeclass="language-json">[
{
"query": "{hero{name}}"
},
{
"query": "{hero{name}}"
}
]
</code></pre>
<p>And then, the response would be in the following array form:</p>