-
Notifications
You must be signed in to change notification settings - Fork 4
/
ShowsDatafetcher.java
32 lines (26 loc) · 1001 Bytes
/
ShowsDatafetcher.java
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.datafetchers;
import com.example.demo.generated.types.Show;
import com.example.demo.services.ShowsService;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsQuery;
import com.netflix.graphql.dgs.InputArgument;
import java.util.List;
import java.util.stream.Collectors;
@DgsComponent
public class ShowsDatafetcher {
private final ShowsService showsService;
public ShowsDatafetcher(ShowsService showsService) {
this.showsService = showsService;
}
/**
* This datafetcher resolves the shows field on Query.
* It uses an @InputArgument to get the titleFilter from the Query if one is defined.
*/
@DgsQuery
public List<Show> shows(@InputArgument("titleFilter") String titleFilter) {
if (titleFilter == null) {
return showsService.shows();
}
return showsService.shows().stream().filter(s -> s.getTitle().contains(titleFilter)).collect(Collectors.toList());
}
}