graphql-compose-mongoose icon indicating copy to clipboard operation
graphql-compose-mongoose copied to clipboard

beforeQuery populate

Open JuanValencia opened this issue 4 years ago • 1 comments

I have virtual fields that I can populate on a mongoose model.

I'd like to have a resolver that uses populate instead of another resolved query.

This is due to the fact that relations are inefficient in certain cases --- consider:

query {
  userMany {
    roles {
      permissions {
        something
        somethingElse
      }
    }
  }
}

If I pull 100 users that all had the same permission, a relation would pull the 100 users in a many (1 query), and then pull the roles (roleMany) 100 times. Populate does 1 query for the user and one query for the role.

Moreover, I'd like then to be able to recursively populate in the GQL query... eg the relation to permissions... like:

User.
  findMany({...}).
  populate({
    path: 'roles',
    populate: { path: 'permissions' }
  });```

JuanValencia avatar Jan 15 '21 01:01 JuanValencia

You should use 'dataLoaderMany' resolver https://github.com/graphql-compose/graphql-compose-mongoose/pull/260#issue-480887824

quangtuan9237 avatar Jul 28 '21 10:07 quangtuan9237