0

Suppose I have below query method defined, Lets say getAllBooks returns 10 books, now if we query for price too, price method will be called multiple times (10 times in this case). How can I batch the call to price method.

@GraphQLQuery(name = "getAllBooks", description = "Get all books")
public List<Book> getAllBooks() {
    return bookService.getAllBooks();
}

@GraphQLQuery
public Long price(@GraphQLContext Book book) {
    return 10L; //In real world problem I want to fetch price from another internal http service.
}

I am looking for solution something similar to posted in below post.

https://jskim1991.medium.com/spring-boot-batching-graphql-queries-with-batchmapping-ed5955835432

Is the DataLoaderRegistryFactory way to go?

  • Provide another function that can take an array of books as parameter, so you call it once and it returns all data at once. Or as an alternative make the first function return the price too. – Alejandro Aug 31 '23 at 17:56

0 Answers0