How to solve N+1 problem using leangen/graphql-spqr

How to solve N+1 problem using leangen/graphql-spqr


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

Not sure what exactly I need to use in graphql-spqr

New contributor

Amit Jolly is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 4 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *