graphql / graphql/dataloader

[Feature request] Remove same length check or auto full fill

Open
#233 5 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
13.4k
Forks
518
Avg merge
2d 4h
Merged PRs (30d)
2

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:
1. Is this length check necessary?or is a little bit over coupled feature?
2. what's the correct pattern to deal with document missing with dataloader?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.