Skip to content

How to modify the BatchMapping Source Object after an operation #1197

@ShreeGiriKumar

Description

@ShreeGiriKumar

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;
}

Metadata

Metadata

Assignees

Labels

status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions