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

Add docs for batching queries and mutations in a single request. #6

Merged
merged 1 commit into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# Summary

* [Introduction](README.md)
* [Quickstart](quickstart.md)
- [Introduction](README.md)
- [Quickstart](quickstart.md)

## Type System

* [Defining objects](types/objects/defining_objects.md)
* [Complex fields](types/objects/complex_fields.md)
* [Using contexts](types/objects/using_contexts.md)
* [Error handling](types/objects/error_handling.md)
* Other types
* [Enums](types/enums.md)
* [Interfaces](types/interfaces.md)
* [Input objects](types/input_objects.md)
* [Scalars](types/scalars.md)
* [Unions](types/unions.md)

- [Defining objects](types/objects/defining_objects.md)
- [Complex fields](types/objects/complex_fields.md)
- [Using contexts](types/objects/using_contexts.md)
- [Error handling](types/objects/error_handling.md)
- Other types
- [Enums](types/enums.md)
- [Interfaces](types/interfaces.md)
- [Input objects](types/input_objects.md)
- [Scalars](types/scalars.md)
- [Unions](types/unions.md)

## Schema

* [Schemas and mutations](schema/schemas_and_mutations.md)
- [Schemas and mutations](schema/schemas_and_mutations.md)

## Adding a server

* [Rocket](servers/rocket.md)
* [Iron](servers/iron.md)
- [Rocket](servers/rocket.md)
- [Iron](servers/iron.md)

## Advanced Topics

* [Non-struct objects](advanced/non_struct_objects.md)
* [Objects and generics](advanced/objects_and_generics.md)
* [Context switching]
* [Dynamic type system]
- [Non-struct objects](advanced/non_struct_objects.md)
- [Objects and generics](advanced/objects_and_generics.md)
- [Context switching]
- [Dynamic type system]
- [Multiple operations per request](advanced/multiple_ops_per_request.md)
71 changes: 71 additions & 0 deletions docs/advanced/multiple_ops_per_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Multiple operations per request

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.

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.

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.

For the following GraphQL query:

```graphql
{
hero {
name
}
}
```

The json data to POST to the server for an individual request would be:

```json
{
"query": "{hero{name}}"
}
```

And the response would be of the form:

```json
{
"data": {
"hero": {
"name": "R2-D2"
}
}
}
```

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:

```json
[
{
"query": "{hero{name}}"
},
{
"query": "{hero{name}}"
}
]
```

And the response would be of the form:

```json
[
{
"data": {
"hero": {
"name": "R2-D2"
}
}
},
{
"data": {
"hero": {
"name": "R2-D2"
}
}
}
]
```