Comments (2)
@Naoto-Ida yeah, you're not using it as intended. In your case, you're giving it a list of Artist IDs, and you're getting back a list of Article IDs for all of those artists mixed. You can either fetch articles by article ID, or do the batching/caching to fetch all articles for an artist per artist, in which case you would return not a list of articles, but a list of lists of articles, i.e. [[article1, article2, ...]]
from dataloader.
@helfer Thanks for the clarification!
I also have other types that contain an articles
field.
So now I've made these loaders:
export const ArtistArticleIdsLoader = new DataLoader((ids) => new Promise((resolve, reject) => {
DOQUERYTOGETARTICLEIDS.then((results) => {
let res = results.map(result => result.id)
resolve(res)
)
}))
export const EventArticleIdsLoader = new DataLoader((ids) => new Promise((resolve, reject) => {
DOQUERYTOGETARTICLEIDS.then((results) => {
let res = results.map(result => result.id)
resolve(res)
)
}))
export const ArticleLoader = new DataLoader((ids) => new Promise((resolve, reject) => {
DOQUERYTOGETARTICLES.then((results) => {
resolve(results)
)
}))
Then in the ArtistType
:
export default new GraphQLObjectType({
name: 'Artist',
fields: () => ({
...
articles: {
type: new GraphQLList(ArticleType),
resolve: (artist, args, ast, { rootValue }) => {
return ArtistArticleIdsLoader.load(artist.id)
.then((articleIds) => {
const promises = articleIds.map(id => ArticleLoader.load(id))
return Promise.all(promises).then(results => results})
})
}
}
})
})
The first two loaders bunch up the ids of articles associated to a certain Artist or Event,
the last loader bunches up the results for those articles.
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.