This repository was archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 535
Request: Batch Client Query #428
Comments
For context, this is how Apollo Server does it. The request body can be an array of objects, in which case they are effectively processed as individual requests and then aggregated and sent back as an array of response objects. |
Here is a simple solution I wrote up until something official is available. Works so far, though I cannot promise I won't find any issues. const runGraphql = graphqlHTTP({
schema,
rootValue,
})
app.use('/graphql', async (req, res, next) => {
// handle batch queries
if(req.body instanceof Array) {
res.origSend = res.send
const origReqBody = req.body
const responseBodies = []
for(let graphqlQuery of origReqBody) {
await new Promise(resolve => {
res.send = body => {
responseBodies.push(body)
resolve()
}
req.body = graphqlQuery
runGraphql(req, res, next)
})
}
res.origSend(`[${responseBodies.join(',')}]`)
return
}
runGraphql(req, res, next)
}) |
This library has been deprecated and this repo will be archived soon. It has been superseded by Furthermore, if you seek a fully-featured, well-maintained and performant server - I heavily recommend GraphQL Yoga! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I am just wondering are we going to have a service that supports batching on the transportation layer? Like how apollo server does. Or do we have to batch on the query level.
The text was updated successfully, but these errors were encountered: