You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to modify the BatchMapping source object right before sending back the response. Imagine there is some db/api exception while fetching ratings for a specific movie and I would like to send that exception info part of the Movie object. Below is a sample snippet and I would like to know if its achievable.
@QueryMapping(name = "getMovies")
public List getAllMovies() {
return Movie.getMovies();
}
@BatchMapping(typeName = "Movie", field = "ratings")
public Map<Movie, List<Rating>> rating(List<Movie> movies) {
// Use the context to get the batch loader
Map<Movie, List<Rating>> movieRatings = movies.stream()
.collect(Collectors.toMap(movie -> movie, movie -> Rating.getById(movie.getId())));
return movieRatings;
}
private Movie modify(Movie movie){
if(movie.getId().equalsIgnoreCase("movie-1")) { //simulating an exception
movie.setError("error while fetching ratings");
return movie;
}
return movie;
}
The text was updated successfully, but these errors were encountered:
@BatchMapping(typeName = "Movie", field = "ratings")
publicMap<Movie, List<Rating>> rating(List<Movie> movies) {
// Use the context to get the batch loaderMap<Movie, List<Rating>> movieRatings = movies.stream()
.collect(Collectors.toMap(movie -> modify(movie), movie -> Rating.getById(movie.getId())));
returnmovieRatings;
}
privateMoviemodify(Moviemovie){
if(movie.getId().equalsIgnoreCase("movie-1")) { //simulating an exceptionmovie.setError("error while fetching ratings");
returnmovie;
}
returnmovie;
}
So, we have the exceptions handled in the service layer. So, the expected response be like,
I am trying to modify the BatchMapping source object right before sending back the response. Imagine there is some db/api exception while fetching ratings for a specific movie and I would like to send that exception info part of the Movie object. Below is a sample snippet and I would like to know if its achievable.
@QueryMapping(name = "getMovies")
public List getAllMovies() {
return Movie.getMovies();
}
The text was updated successfully, but these errors were encountered: