wesleyyoung / perch-query-builder

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

Question: Is there a way to use `FindManyOptions<Type>` with `PerchQueryBuilder`? #7

Closed Migushthe2nd closed 3 years ago

Migushthe2nd commented 3 years ago

Using the built-in repository find() method, it is possible to find with many different options (image below) image

Is there a way to specify such options with PerchQueryBuilder?

wesleyyoung commented 3 years ago

Are you asking if you can supply additional filter params on top of the query?

This is actually possible if you instead use const qb = PerchQueryBilder.generateQueryBuilder(this.bookRepository, info)

and attach additional AND WHERE clauses. The generateQueryBuilder method returns a TypeORM QueryBuilder

Migushthe2nd commented 3 years ago

Ah I see, I can always use the general querybuilder, however, I prefer the simplicity of Repository.find(). This allows one to do quite a lot actually, even filter on nested types. A simple example would be:

bookRepository.find({
    where: {
        status: In(["Free", "Sale"])
        publisher: {
            id: "5b"
        }
    }
})

Edit: The QueryBuilder's where() method accepts an object of type FindOptions<Type>. (queryBuilder.where(findOptions))