Open
Description
What problem are you trying to solve?
“DataLoader must be constructed with function which accepts Array and returns Promise>, but the function did not return a Promise of an Array of the same length as the Array of keys”
Describe the solution you'd like
In practice using a NoSql database like mongodb, some referenced document missing is not a serious problem, but this length check make things terrible, for example
user1 = { id: ObjectId(user1) }
user2 = {id: ObjectId(user2) }
// user3 has been deleted, but associated data has not been cleaned yet.
post1 = {id: ObjectId(post1), author: ObjectId(user3) } // here reference user3 is not exist now
post2= {id: ObjectId(post2), author: ObjectId(user1) }
post3= {id: ObjectId(post3), author: ObjectId(user2) }
// now if I make a dataloader for Users, the array length obviously not equal !!
const usersLoader = new DataLoader(
keys => async (keys, {Users}) => {
return await Users.find({id: {$in: keys}}).toArray()
},
{ cacheKeyFn: key => key.toString() }
)
Describe alternatives you've considered
My questions are:
- Is this length check necessary?or is a little bit over coupled feature?
- what's the correct pattern to deal with document missing with dataloader?