-
Notifications
You must be signed in to change notification settings - Fork 153
Description
Right now for each Book, GraphQL is making a new request to the database in order to retrieve the Book Author By it's id, but this could be done in batch to avoid N+1 queries to get a list a books with the authors.
That could be made by implementing a method in AuthorRepository that retrieves a list of authors based in a list a ids. After that it would be necessary to implement a BatchLoader that by a list of keys, gets a list of Authors by delegating the request to the AuthorRepository. Once you've done that you just have to implement a GraphQLContextBuilder, registering a DataLoader that uses the BatchLoader implementation and then, in BookResolver, instead of making the request directly to the AuthorRepository, you could do this request by getting the DataLoader you registered from a DataFetchingEnvironment.