Dr.Dennis B
Dr.Dennis B

Reputation: 47

dataloader facebook optimization

everybody! I'm trying to use Dataloader by facebook in my graphql project. So, now I'm faced to the next problem. When I ask my database for data by ids for example: select * from books where books.author in (4,5,6,7) I got an Error: "function did not return a Promise of an Array of the same length as the Array of keys". Cause by id 4 I can fetch more then just one book. Does anybody know how to fix it?

Upvotes: 0

Views: 146

Answers (2)

xadm
xadm

Reputation: 8418

You should return an array for each id - array of arrays. You have to convert sql result - flat list with duplicates into 'groupped' arrays of records preserving input ids (amount and order).

Upvotes: 0

adrice727
adrice727

Reputation: 1492

Dataloader is expecting you to return an array of the same length as the input to your loader. So, if the loader gets [4,5,6,7] as an input, it will need to return an array with a length of 4. Also keep in mind that the results returned from the loader need to be in the same order as the input ids. This may or may not be something you have to worry about depending on how the data is returned from your database.

Upvotes: 1

Related Questions