Comments (5)
Any update on that?
from dataloader.
Hi.
Although that's a good point. We shouldn't change that behaviour as it would braek a lot of code using loadMany expecting to be able to catch after an error.
As stated in the doc loadMany is just a utility fonction and it serves as a dumb shortcut and It would be very easy for you to handle this case yourself.
Looking at loadMany implementation:
return Promise.all(keys.map(key => this.load(key)));
You can just do your own version of it like so
function myLoadMany(keys) {
return Promise.all(
keys.map(key => loader.load(key).catch(err => new Error(err))
);
}
Hope it helped
from dataloader.
Hey @BartKrol - I think this is an interesting idea, but it's true that it would be a breaking change to the API.
Perhaps it was a mistake to include loadMany
from the beginning since it was such a small convenience wrapper on Promise.all
- I agree that it's perhaps more interesting if it provides behavior different from the more typical Promise.all usage.
Another challenge to consider is how to detect the difference between an Error object and a value - right now the library is using instanceof Error
- but this is well known to be fragile if your environment spans JS realms. Not always a real problem, but can be in edge cases, right now an edge case not exposed.
from dataloader.
I think we are talking about two separate problems here.
First one is a problem with loadMany
method, which, as you explained, is just a wrapper around Promise.all
. I guess you are right and this shouldn't be changed.
The second problem is something different. I consider a new Error
in a load
method as a perfectly valid response - after all I'm returning an error and not throwing it. Here's a code example:
function createByIdLoader(loadFunc) {
return new DataLoader(
ids => Promise.all(
ids.map(loadFunc)
),
{
cache: false
}
)
}
describe('DataLoader', () => {
it('should return an error', () => { // Failing
const value = 'fail'
const stub = sinon.stub().returns(Promise.resolve(new Error(value)))
const loader = createByIdLoader(stub)
return loader.load(1).then(error => {
expect(error).to.deep.equal(new Error(value))
})
.catch((err) => {
console.log('Should never be here')
throw err
})
})
})
from dataloader.
Sorry for letting this issue sit, I'll be closing it since it's starting to age.
Unfortunately DataLoader needs to use the Error returning behavior to determine mixed results from a Batch. Throwing an error would indicate that the entire batch request failed, however in the case that the batch request itself succeeded but some of the values within it failed, then an appropriate result is to return the list of resolved values where some values at indexes are Error instances instead of values.
from dataloader.
Related Issues (20)
- Move CI to GitHub Actions
- Setup publish token for CI
- Change default branch `master` to `main` HOT 1
- Setup Renovate Bot to keep dependencies up to date HOT 3
- [QUESTION] Why aren't keys being de-duplicated even when the cache is disabled? HOT 6
- ✨ [REQUEST]: Add examples for cacheKeyFn and cacheMap HOT 2
- [REQUEST]: How to pass auth headers to dataloader HOT 4
- [QUESTION] README.md doesn't show on npmjs.com HOT 2
- CacheMap.get calls should await the promised value HOT 1
- [QUESTION] Release changes? HOT 9
- [QUESTION] name is now required in options? HOT 4
- [BUG] Readme is missing from NPM HOT 2
- [BUG] `this` context not available in typescript definitions
- [BUG] Use caution with `jest.useFakeTimers()` HOT 1
- [REQUEST] support vercel edge functions by default HOT 4
- Ever considered the use of `queueMicrotask`? HOT 1
- Coalescing multiple load() calls HOT 3
- [REQUEST] Unify the way `load` and `loadMany` handle errors
- -
- [REQUEST] Add batch grouping
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dataloader.