Skip to content

Make Batch calls instead of getting each Author by Id at a time. #17

Description

@pedroviniv

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions