includes/eager load associated models with graphql-ruby

Viewed 744

I've been searching for examples on how to translate a traditional ActiveRecod .includes for associated models, while using graphQL-ruby, and haven't found any. As a use case, let's say we have the following models:

User
has_many :books

Book
belongs_to :user
has_many :chapters

Chapter
belongs_to :book
has_many :pages

Page
belongs_to :chapter

How could we implement the following:

User.includes(books: {chapters: :pages})

The actual nested GraphQL query is relatively simple; however, it seems to be running at N+1.

Any help would be greatly appreciated.

2 Answers
Related