Graphql: How can I solve the N + N problem?

After having implemented dataloader in the respective resolvers to solve the N+1 problem, I also need to be able to solve the N+N problem.

I need a decently efficient data loading mechanism to get a relation like this:

{
  persons (active: true) {
    id,
    given_name,
    projects (active: true) {
      id,
      title,
    }
  }
}

I’ve created a naive implementation for this, returning

{
  persons: [
    {
      id: 1,
      given_name: 'Mike'
      projects: [
        { 
          id: 1,
          title: 'API'
        },
        { 
          id: 2,
          title: 'Frontend'
        }      
      ]
    } 
    {
      id: 2,
      given_name: 'Eddie'
      projects: [
        { 
          id: 2,
          title: 'Frontend'
        },      
        { 
          id: 3,
          title: 'Testing'
        }
      ]
    } 
  ]
}

In SQL the underlying structure would be represented by a many many to many relationship.

Is there a similiar tool like dataloader for solving this or can this maybe even be solved with dataloader itself?

Read more here: Source link