Application Scoped DataLoader #763
-
|
Is there a way to configure the framework to reuse DataLoaders so they will be application scoped and not request scoped? As much as I understand the DgsDataLoaderProvider is creating new DataLoaders per request and with application scoped data loaders multiple http requests will be batched to perform a single DB query. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
DataLoaders are designed to batch (database/backend) calls within a single request. This is required because a field datafetcher, which might need to load from an external datasource, will be invoked for each instance of its parent. Doing something similar for multiple requests adds many complications. Just to give some examples:
Although there might be answers to these questions for highly specialized scenarios, the mechanism won't work in most cases. For scenarios it would work, it would probably be better to leverage caching instead of trying to batch. |
Beta Was this translation helpful? Give feedback.
DataLoaders are designed to batch (database/backend) calls within a single request. This is required because a field datafetcher, which might need to load from an external datasource, will be invoked for each instance of its parent.
E.g. if I have a DataLoader for
Product.price, and I load 500 products from aQuery.productsquery, theProduct.pricedatafetcher will be called 500 times. IfProduct.pricewould call out to a database, we would need to batch that.Doing something similar for multiple requests adds many complications. Just to give some examples: