Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit 9f77ea9

Browse files
authored
Add docs for batching queries and mutations in a single request. (#6)
Support was added in graphql-rust/juniper#171 and asked about in graphql-rust/juniper#214.
1 parent a2ffbf8 commit 9f77ea9

File tree

2 files changed

+91
-20
lines changed

2 files changed

+91
-20
lines changed

docs/SUMMARY.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
# Summary
22

3-
* [Introduction](README.md)
4-
* [Quickstart](quickstart.md)
3+
- [Introduction](README.md)
4+
- [Quickstart](quickstart.md)
55

66
## Type System
77

8-
* [Defining objects](types/objects/defining_objects.md)
9-
* [Complex fields](types/objects/complex_fields.md)
10-
* [Using contexts](types/objects/using_contexts.md)
11-
* [Error handling](types/objects/error_handling.md)
12-
* Other types
13-
* [Enums](types/enums.md)
14-
* [Interfaces](types/interfaces.md)
15-
* [Input objects](types/input_objects.md)
16-
* [Scalars](types/scalars.md)
17-
* [Unions](types/unions.md)
18-
8+
- [Defining objects](types/objects/defining_objects.md)
9+
- [Complex fields](types/objects/complex_fields.md)
10+
- [Using contexts](types/objects/using_contexts.md)
11+
- [Error handling](types/objects/error_handling.md)
12+
- Other types
13+
- [Enums](types/enums.md)
14+
- [Interfaces](types/interfaces.md)
15+
- [Input objects](types/input_objects.md)
16+
- [Scalars](types/scalars.md)
17+
- [Unions](types/unions.md)
1918

2019
## Schema
2120

22-
* [Schemas and mutations](schema/schemas_and_mutations.md)
21+
- [Schemas and mutations](schema/schemas_and_mutations.md)
2322

2423
## Adding a server
2524

26-
* [Rocket](servers/rocket.md)
27-
* [Iron](servers/iron.md)
25+
- [Rocket](servers/rocket.md)
26+
- [Iron](servers/iron.md)
2827

2928
## Advanced Topics
3029

31-
* [Non-struct objects](advanced/non_struct_objects.md)
32-
* [Objects and generics](advanced/objects_and_generics.md)
33-
* [Context switching]
34-
* [Dynamic type system]
30+
- [Non-struct objects](advanced/non_struct_objects.md)
31+
- [Objects and generics](advanced/objects_and_generics.md)
32+
- [Context switching]
33+
- [Dynamic type system]
34+
- [Multiple operations per request](advanced/multiple_ops_per_request.md)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Multiple operations per request
2+
3+
The GraphQL standard generally assumes there will be one server request for each client operation you want to perform (such as a query or mutation). This is conceptually simple but has the potential to be inefficent.
4+
5+
Some client libraries such as [apollo-link-batch-http](https://www.apollographql.com/docs/link/links/batch-http.html) have added the ability to batch operations in a single HTTP request to save network round-trips and increase performance.
6+
7+
Juniper's [`Rocket`](servers/rocket.md) and [`Iron`](servers/iron.md) server integrations support multiple operations in a single HTTP request using JSON arrays. This makes them compatible with client libraries that support batch operations without any special configuration.
8+
9+
For the following GraphQL query:
10+
11+
```graphql
12+
{
13+
hero {
14+
name
15+
}
16+
}
17+
```
18+
19+
The json data to POST to the server for an individual request would be:
20+
21+
```json
22+
{
23+
"query": "{hero{name}}"
24+
}
25+
```
26+
27+
And the response would be of the form:
28+
29+
```json
30+
{
31+
"data": {
32+
"hero": {
33+
"name": "R2-D2"
34+
}
35+
}
36+
}
37+
```
38+
39+
If you wanted to run the same query twice in a single HTTP request, the batched json data to POST to the server would be:
40+
41+
```json
42+
[
43+
{
44+
"query": "{hero{name}}"
45+
},
46+
{
47+
"query": "{hero{name}}"
48+
}
49+
]
50+
```
51+
52+
And the response would be of the form:
53+
54+
```json
55+
[
56+
{
57+
"data": {
58+
"hero": {
59+
"name": "R2-D2"
60+
}
61+
}
62+
},
63+
{
64+
"data": {
65+
"hero": {
66+
"name": "R2-D2"
67+
}
68+
}
69+
}
70+
]
71+
```

0 commit comments

Comments
 (0)