-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Dataloader, PersonType, and some data to test it. #1303
Conversation
This is great, I was just planning on doing something very similar, so thank you! What is a little confusing for me here is that you aren't retrieving people by querying Sequelize, which would be the whole point of using DataLoader in practice? |
It never crossed my mind lol. I haven't used Sequelize in over a year and couldn't see any docs on setting the project up with it. Unfortunately I will be busy for the next month doing video production work though so I won't be able to get it up and running anytime soon. If you were wanting to set it up and have questions feel free to ask. I have a project in heavy development ontop of Google Cloud Platform's Datastore + relay-modern/ graphql connections if your interested in looking at as well (my pull request is pretty much a copy of how dataloader is being used in it). That repo is here: https://github.com/DaveyEdwards/myiworlds |
Sequelize and an empty sqlite3 database actually come packaged with RSK these days, which is why I brought it up I posted some code for accessing the db the other day via Sequelize issues/1296 for similar purposes Querying the database responsibly is something I will need to sort out one way or another. Thanks for the links! |
Implementing this wasn't anywhere near as hard as I had thought, if it helps here is a run down of adding new dataloaders or how you would integrate it with sequelize:
export default {
personLoader: new DataLoader(people => Promise.all(people.map(_id => getPerson(_id)) ))
}
// Import your new loader
import personLoader from './personLoader';
// All your dataloaders
const allLoaders = {
// Add your new loader here
...personLoader
}
export default function loaders () {
return allLoaders
} This is where in the server.js file it is getting those loaders and using them. pretty: __DEV__,
context: {
loaders: loaders()
},
})));
friends: {
type: new List( PersonType ),
resolve: async( person, args, { loaders }) => {
return await loaders.personLoader.loadMany( person.friends );
}
} That's it. Some documentation like this would have been extremely helpful for people like me just last week lol. If this gets accepted or gets some changes I think I will re write this with better examples to add to the docs, maybe do a video to |
"dataloader": "^1.3.0", | ||
"express": "^4.15.2", | ||
"express-graphql": "^0.6.4", | ||
"dataloader": "^1.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dataloader two times
@DaveyEdwards thank you very much for this PR! Unfortunately, we have close it due to inactivity. Feel free to re-open it or join our Discord channel for discussion. NOTE: The |
Here is a pull request adding Dataloader to the project. If you log the response coming out of the getPerson you can see that it is only getting each person once.
Only thing I am unsure of is on large nested queries it starts to slowdown quite abit, but I think it is the way the 'seed/people' are being referenced in my getPerson function. Would appreciate any input.
When I query my db of Google Datastore with this same setup I get amazing performance on 700 lined nested queries.
Here is a gif demonstrating the queries/different sizes with what I have in the pull request
(last query takes around 20seconds to display and about 5min before I can scroll through the data. It is around 57mb in size)