Search code examples
graphqlgraphql-java

GraphQL bulk resolve / Prevent complex type request overhead


Assume we have a model Book which contains another model Author.
Now lets send a query like:

query Book {
    newestBooks(count: 200) {
        id
        title
        author {
            name
        }
    }
}

In my BookResolver I provide a method getAuthor() which is called once for each Book.
If the getAuthor() method loads the author from another service over the network or from the database a lot of overhead will occur for a large number of Books.

Is there a way in GraphQL to do some kind of a bulk request for populating the author field of the n Book instances?

I am evaluationg GraphQL with Java and Spring Boot, but I guess this topic is only concept and not environment related...


Solution

  • You are probably looking for the DataLoader concept. DataLoader ported to Java is available here.