Had a tricky situation where my UI was trying to load profile info for 5000 profiles (for #ahau)... and apollo apparently just shits itself if you make that many concurrent requests.
So I made a janky queue with pull-streams:
const pull = require('pull-stream')
const Pushable = require('pull-pushable')
const pullParaMap = require('pull-paramap')
const queue = Pushable()
pull(
queue,
pullParaMap(
([runPromise, resolve, reject], cb) => {
runPromise()
.then(resolve)
.catch(reject)
.finally(() => cb(null))
},
10 // how many runPromise you can run concurrently
),
pull.drain()
)
// My vuex action that was getting hammered
// actions here play well with Promises
async function getPersonMinimal (_, profileId) {
// make a Promise (so we can return some thing)
return new Promise((resolve, reject) => {
// set a our query *ready* to be run
const runQuery = async () => {
try {
const res = await apollo.query(getPersonMinimal(profileId))
if (res.errors) throw res.errors
return res.data.person
} catch (err) {
// oh no!
}
}
// stick this in the queue of things to run,
// along with the resolve / reject for handling the results
queue.push([runQuery, resolve, reject])
})
}