doug-martin / nestjs-query

Easy CRUD for GraphQL.
https://doug-martin.github.io/nestjs-query
MIT License
822 stars 142 forks source link

[Question] - Filter on Relation fields #223

Closed rshriyan-weco closed 4 years ago

rshriyan-weco commented 4 years ago

Hello Doug

I started working on GraphQL just this week so I am a total beginner. I came across your abstraction for CRUD operation's and it seems to fit my requirement very well. I do have a question for you. I have the following relation(Psuedo code):

class Car {
  name: string;
  @OnetoOne() manufacturer: Manufacturer
}

class Manufacturer {
  name: string;
}

Frontend client is showing all of this data as flat list meaning:

Car Name | Manufacturer Name

With the standard setup and by using Relations from your library, everything works well. However those fields should be filterable specifically the manufacturer name. Does this require me to implement my own CRUD resolver and sort of have a flat list DTO to represent the flat list the frontend expects ?

doug-martin commented 4 years ago

This package doesnt currently support filtering on relation values.

One way to achieve this is to think about the problem slightly differently, instead of using car as root of your query instead query for manufacturers with the name you want to query for and include their cars.

renehauck commented 4 years ago

I guess the problem is that in my opinion it is not always possible to solve the problem that way. :disappointed: For example if you want to implement a table in a frontend where one entry has many relations (A person who has a contact information, an address etc). If you now want to filter/sort by address, would you already have a problem, or do I get something wrong? For me and I think others, this would be a very important feature. :grinning:

bestickley commented 4 years ago

@doug-martin, would it be possible to update the FilterBuilder to be recursive and allow for something like this: { role: { name { is: "Admin" } } on an User entity where role is a Role entity related to User?

doug-martin commented 4 years ago

@rshriyan @bestickley @renehauck this enhancement has been published under v0.16.0.

You can read more about this feature in the following docs

Thank you for the enhancement request!