Batching queries
You can minimize network requests and server load fetching queries that are near in time using batching.
Remember that to use batching you need a graphql server that supports it, for example Apollo and Hasura
import { createClient } from './generated'
const client1 = createClient({
batch: true, // use defaults
})
const client2 = createClient({
batch: {
batchInterval: 100, // ms
maxBatchSize: 10,
},
})
// these queries will trigger only one network request
await Promise.all([
client.query({
user: {
age: true,
},
}),
client.query({
user: {
id: true,
},
}),
client.query({
user: {
name: true,
},
}),
])