-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add: nested filter input-types #143
Conversation
To configure the filter-depth for an entity, you pass the @ObjectType('TodoItem')
// `filterDepth` is a number, 1 is the default
@QueryOptions({ filterDepth: 3 })
// `filterDepth: Number.POSITIVE_INFINITY` will result in a infinitely deep filter
@QueryOptions({ filterDepth: Number.POSITIVE_INFINITY })
export class TodoItemDTO {
@IDField(() => ID)
id!: number;
@FilterableField()
title!: string;
@FilterableField({ nullable: true })
description?: string;
@FilterableField()
completed!: boolean;
@FilterableField(() => GraphQLISODateTime)
created!: Date;
@FilterableField(() => GraphQLISODateTime)
updated!: Date;
} |
Codecov Report
@@ Coverage Diff @@
## master #143 +/- ##
==========================================
+ Coverage 78.16% 78.31% +0.15%
==========================================
Files 619 626 +7
Lines 8682 8771 +89
Branches 831 839 +8
==========================================
+ Hits 6786 6869 +83
+ Misses 1169 1167 -2
- Partials 727 735 +8
... and 2 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thanks for the PR! Could you show me a query filter example that before did work and does not now? I'm not quite sure I completely understand what this does. |
This PR implements the feature to generate infinitely deep input-filter-types (doug-martin/nestjs-query#805 and #121).
No because the problem with the query-builder only occurs if the nesting is deeper than one level, which is impossible until now. But this PR changes that, that's why I stumbled upon this bug. But this PR is only for the infinitely deep filters. |
return filterableRelations | ||
} | ||
|
||
function getOrCreateFilterType<T>(TClass: Class<T>, name: string, depth = 0): FilterConstructor<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we call getOrCreateFilterType
already with dept = 1 do we need the dept = 0
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because we call it with depth = 1
only on the (Delete / Update / Subscription / Aggregate)FilterType
. The base FilterType
is called without an argument.
What we can do is to remove the default value and move the depth = 0
into the base FilterType
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay check, maybe indeed call it there with dept = 0
so we don't need the default.
So if I understand correctly, default it create a |
Exactly. |
And a question: If we where to release this like this it will not change any schema except if you provide the |
Nope, otherwise the test wouldn't have passed. |
True, thought of that after I send it 😅 Everything looks ok, it's a nice addition this so thanks for that! If the other tasks are also completed we can merge and release! |
Should be ready now @TriPSs 🚀 |
Thanks for the PR! Changes look good, I do want to check this out locally before merging if you don't mind. |
@hedwiggggg after checking this locally I did notice one thing: @FilterableRelation('relation', () => Relation, {
// This one does not work
filterDepth: 2,
}) Can we either remove it or add support for it? (I do think it's nice we can specific it for a specific relation instead of all relations) |
Unfortunately, this can only be realized with breaking changes, since the target depth would have to be embedded in the filter name. Otherwise, it cannot be guaranteed which filter depth will be generated because the root filter names are the same for different depths. And configuring each relation individually, would possibly lead to different depths for the same filter type. I have specially designed this feature so that there are no breaking changes. |
tldr; we would need to generate In the following example we would need 3 different filter types, but in the current implementation all filter types would have the same name, which is invalid in GraphQL.
|
Understandable, could we then remove it from there so the option is not shown? |
I thought about it again last night. There is a way to configure this per relation, without breaking-changes. By default the filter depth is 1. With this filter depth the generated name can also be
But nevertheless I would take it out for now and put the feature-request into a separate issue, since I don't have the resources for it right now. Edit: above assumption is complete bs, because the parentEntity-name is prefixed for n-depth filters. A better example would be: // Example-A.entity.ts
@ObjectType('EntityA')
@FilterableRelation('relation', () => relation)
class EntityA { /* ... */ }
// leads to
// input EntityAFilter {
// relation: EntityAFilterRelationFilter
// } // Example-B.entity.ts
@ObjectType('EntityB')
@FilterableRelation('relation', () => relation, { filterDepth: 2 )
class EntityB { /* ... */ }
// leads to
// input EntityBFilter {
// relation: EntityBFilterRelationFilter
// } This means that we don't get name conflicts when we specify a |
@hedwiggggg massive thanks for this addition! |
Hello, in this pull request I added the possibility to create filter types at any depth. So far I have only run the unit-tests.
So still missing:
Internal tests already ran successfully, but I noticed a bug with the query builder. In the generated joins the alias is set to the filter-property. So a hypothetical filter like this:
Ends with the error:
table name "group" specified more than once
. Here is the log:But this is a problem for an own issue / pull request.