3 ms·
The Python Graphql library Graphene-Django includes built-in support for dataloaders, and you can just tell it how to load a list of objects, given their id's (
by Ozzie_osman 6y ago
The Python Graphql library Graphene-Django includes built-in support for dataloaders, and you can just tell it how to load a list of objects, given their id's (by default, use the foreign key id as the primary key). Works beautifully.
- yeswecatan 6y agoI haven't had a chance to dig into dataloaders much. Is the basic idea you perform one query per "layer?" Maybe not as great as just using something like A.objects.prefetch_related(related_objects__other_object), but better than N+1
- Ozzie_osman 6y ago(Sorry for the delay here) At face value, it can issue one more query per layer, but you get a lot of other benefits by breaking down your logic in this way. For example, you're less inclined to use database joins that may not scale as you grow. Another benefit is that you can very easily switch storage layers. For instance, maybe you fetch one layer from your SQL database, and another from a KV store database. Or maybe one layer comes from the cache, etc.