How use data loaders ? #1451
Replies: 2 comments
-
Can you provide some more details on what you want ? |
Beta Was this translation helpful? Give feedback.
-
This really depends on how the models are structured, but for any complex application, GraphQL's nested structure will result in multiple calls to the same data sources. Facebook came up with something called DataLoader to batch and cache these calls. DataLoader is first and foremost a data loading mechanism, and its cache only serves the purpose of not repeatedly loading the same data in the context of a single request to the application. I think the ask is for SmallRye GraphQL to add support to it as well. For instance, Netflix's DGS Framework integrated that somehow, and they can do things like: @DgsDataLoader(name = "nameTheDataLoader")
public class ModelDataLoader implements BatchLoader<String, Model> {
@Override
public CompletionStage<List<Model>> load(Collection<String> keys) {
return CompletableFuture.supplyAsync(() -> service.getModelByAGivenCriteriaFrom(keys));
}
} ...then in the resolvers: DataLoader<String, Model> dl = dgsDataFetchingEnvironment.getDataLoader("nameTheDataLoader"); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, first thanks for great work, how use data loaders with this library ?
Beta Was this translation helpful? Give feedback.
All reactions