wesleyyoung / perch-query-builder

Dynamically build TypeORM queries based on GraphQL queries for NestJS and TypeORM
GNU General Public License v3.0
45 stars 9 forks source link

Question: how can I ignore fields and fetch based on a nested field? #10

Open Migushthe2nd opened 2 years ago

Migushthe2nd commented 2 years ago

My query has the following structure:

query {
  items(limit: 50) {
    pageInfo {
      page
    }
    nodes {
      id
    }
  }
}

here nodes are my repository entities. I'd like to implement my own pagination logic. PerchQueryBuilder tries to build the query starting from the root fields (pageInfo, nodes), however, these are not in any entitity and only in the model. This causes the following to return an empty array:

const queryBuilder = PerchQueryBuilder.find(this.repository, info)
// query: SELECT * FROM "typeorm"."entity" "Entity"
const res = await queryBuilder
console.log(res)
// -> []

Is it possible to make PerchQueryBuilder treat nodes as the root?