()
| 48 | } |
| 49 | |
| 50 | private dispatchBatches() { |
| 51 | for (const key in this.batches) { |
| 52 | const batch = this.batches[key] |
| 53 | delete this.batches[key] |
| 54 | |
| 55 | // only batch if necessary |
| 56 | // this might occur, if there's e.g. only 1 findUnique in the batch |
| 57 | if (batch.length === 1) { |
| 58 | this.options |
| 59 | .singleLoader(batch[0].request) |
| 60 | .then((result) => { |
| 61 | if (result instanceof Error) { |
| 62 | batch[0].reject(result) |
| 63 | } else { |
| 64 | batch[0].resolve(result) |
| 65 | } |
| 66 | }) |
| 67 | .catch((e) => { |
| 68 | batch[0].reject(e) |
| 69 | }) |
| 70 | } else { |
| 71 | batch.sort((a, b) => this.options.batchOrder(a.request, b.request)) |
| 72 | this.options |
| 73 | .batchLoader(batch.map((j) => j.request)) |
| 74 | .then((results) => { |
| 75 | if (results instanceof Error) { |
| 76 | for (let i = 0; i < batch.length; i++) { |
| 77 | batch[i].reject(results) |
| 78 | } |
| 79 | } else { |
| 80 | for (let i = 0; i < batch.length; i++) { |
| 81 | const value = results[i] |
| 82 | if (value instanceof Error) { |
| 83 | batch[i].reject(value) |
| 84 | } else { |
| 85 | batch[i].resolve(value) |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | }) |
| 90 | .catch((e) => { |
| 91 | for (let i = 0; i < batch.length; i++) { |
| 92 | batch[i].reject(e) |
| 93 | } |
| 94 | }) |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | get [Symbol.toStringTag]() { |
| 100 | return 'DataLoader' |
no test coverage detected