TriPSs / nestjs-query

Easy CRUD for GraphQL.
https://tripss.github.io/nestjs-query/
MIT License
152 stars 43 forks source link

Extend nested filter input-types to allow filter-depth configuration per relation. #145

Open hedwiggggg opened 1 year ago

hedwiggggg commented 1 year ago

Extend nested filter input-types (https://github.com/TriPSs/nestjs-query/pull/143) to allow filter-depth configuration per relation.

@FilterableRelation('relation', () => Relation, {
  // This one does not work yet
  filterDepth: 2,
})

Describe the solution you'd like

Requires further customization in the /nestjs-query/packages/query-graphql/src/types/query/filter.type.ts file. At Object.keys(filterableRelations).forEach((field) => { the filterDepth of the relation should be considered (only if set), not the filterDepth of the parent element.

// Example-A.entity.ts
@ObjectType('EntityA')
@FilterableRelation('relation', () => relation)
class EntityA { /* ... */ }

// leads to
// input EntityAFilter {
//    # should generate depending on the `filterDepth` of `EntityA`
//    relation: EntityAFilterRelationFilter
// }
// Example-B.entity.ts
@ObjectType('EntityB')
@FilterableRelation('relation', () => relation, { filterDepth: 2 )
class EntityB { /* ... */ }

// leads to
// input EntityBFilter {
//     # should generate a filter type of depth 2
//     relation: EntityBFilterRelationFilter
// }

This is not a critical feature for me personally, so I will look at this in the future when I have more resources available again.

qashlan commented 2 months ago

any updates regarding this

hedwiggggg commented 2 months ago

Nope, sorry. Still not really a critical feature for me. But feel free to create a PR, if you need this feature 😄 @qashlan

qashlan commented 2 months ago

@hedwiggggg sure, will put sometime into this.