Skip to content

Optimization for relations of relation #25

@hardfire

Description

@hardfire

I have created a small example where the model is like the following

 Student --- hasMany ---> Homework --- hasMany -----> Page

Now, when I load the following (note: viewer is the student) the there is one query for the student, one for the homework, but multiple for the pages. There are as many queries as there are pages. How can i optimize it so that there is only one query for the all the pages.

Best case scenario would be to load the whole thing at once, but i'd be happy for any pointers on how to optimize this.

{ 
 viewer(id: 3) {
    name
    homeworks{
      subject
      pages{
        content
      }
    }
  }
}

The code i used to test this is available at https://gist.github.com/hardfire/3ff69d3a602bf3c30dcbbca71d67d605

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