mickhansen / dataloader-sequelize

Batching and simplification of Sequelize with facebook/dataloader
MIT License
284 stars 58 forks source link

Association Usage questions #109

Closed kennetpostigo closed 3 years ago

kennetpostigo commented 4 years ago

Hi,

I have a 2 questions about usage of dataloader-sequelize:

  1. When using dataloader-sequelize with include does it appropriately cache the associations by their model? So for example if I were to grab a User and use include to also grab their Post, does it all get cached under that user? Or does the User get cached for user models and Post get cached with post models?

  2. When using dataloader-sequelize if I were to grab a User and then use the User association method getPost to grab their Post data, does the dataloader-sequelize hook into the association and check the cache first?

mickhansen commented 4 years ago

Are you using this in context of GraphQL or are you using it standalone?

kennetpostigo commented 4 years ago

@mickhansen we're using this in context of GraphQL

mickhansen commented 4 years ago

@kennetpostigo Then i would not suggest using includes at all.

kennetpostigo commented 4 years ago

How come?

mickhansen commented 4 years ago

Using includes would require reasoning about all the subfields of the field you are currently looking at, it's not impossible but has a few pitfalls.

I'd suggest simply resolving for each field and let dataloader make sure you end up with only 1 query.

kennetpostigo commented 4 years ago

Curious what the technical limitations are and where I can pitch in to make the cache more easily normalized, any guidance you can give @mickhansen would be awesome, would love to pitch in.

mickhansen commented 4 years ago

I honestly don't recall what level of support we have for includes at this time. An earlier version of graphql-sequelize tried to reason about it but it was more trouble than it's worth as you only really gain a benefit with 1:1 associations.

oney commented 4 years ago

@kennetpostigo you might want to check this out https://github.com/oney/sequelize-proxy It includes internal data loaders to batch any associations(hasOne, belongsTo, hasMany, belongsToMany) with where, order, limit and scopes.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.