-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathReviewsDataLoader.java
More file actions
32 lines (26 loc) · 1.13 KB
/
ReviewsDataLoader.java
File metadata and controls
32 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.example.demo.dataloaders;
import com.example.demo.generated.types.Review;
import com.example.demo.services.DefaultReviewsService;
import com.netflix.graphql.dgs.DgsDataLoader;
import org.dataloader.MappedBatchLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
@DgsDataLoader(name = "reviews")
public class ReviewsDataLoader implements MappedBatchLoader<Integer, List<Review>> {
private final DefaultReviewsService reviewsService;
public ReviewsDataLoader(DefaultReviewsService reviewsService) {
this.reviewsService = reviewsService;
}
/**
* This method will be called once, even if multiple datafetchers use the load() method on the DataLoader.
* This way reviews can be loaded for all the Shows in a single call instead of per individual Show.
*/
@Override
public CompletionStage<Map<Integer, List<Review>>> load(Set<Integer> keys) {
return CompletableFuture.supplyAsync(() -> reviewsService.reviewsForShows(new ArrayList<>(keys)));
}
}