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

Implement `@SelectAlways()` decorator #19

Open Migushthe2nd opened 2 years ago

Migushthe2nd commented 2 years ago

This is related to the (closed) issue https://github.com/wesleyyoung/perch-query-builder/issues/8. This PR implements my proposal of a @SelectAlways() decorator for columns.

I found that if using, for example, an @AfterLoad() that depends on fields in the entity, it would be cleaner to use a decorator instead of manually adding addSelects for the fields (like you suggested). I originally considered to encapsulate the PerchQuerybuilder.generateQueryBuilder() with a custom function in order to add the selects, however, I don't think it is ideal to hardcode a list of fields that should be selected, thus this PR.

This implementation only force-selects the column when its class relation is in the query:

parent (in query)
     child (not in query)
          property (not selected)

parent (in query)
     child (in query)
          property (selected)