Skip to content
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 where filter for relational objects aswell? #13

Open
anthonyhoegberg opened this issue Jun 12, 2024 · 7 comments
Open

Add where filter for relational objects aswell? #13

anthonyhoegberg opened this issue Jun 12, 2024 · 7 comments
Assignees

Comments

@anthonyhoegberg
Copy link

anthonyhoegberg commented Jun 12, 2024

Right now we can only do where filters on properties of objects
But being able to filter on relations aswell would be nice bc we could do the following:

query Example{
    user(
      where: {
            relationComment: {
                isNotNull: true
            }
        }
    ){
      username
      relationComment(where: {
        comment: {
          eq: "test"
        }
      }){
        comment
      }
    }  
}

Right now even if we would filter the comments, we would still get all users that does not have a comment that equals test, so we would get a list of all usernames including those without the test comment

We could inverse the query and go from comments where it equals test and the including users inside of that as reference to parent object, but in some circumstances that does not make sense. (like having other filters on the user object itself)

EDIT:

Its also currently not possible to limit/offset relational objects only where for its sub properties

@Sukairo-02 Sukairo-02 self-assigned this Jun 12, 2024
@Sukairo-02
Copy link
Collaborator

Offset, limit & order by are excluded from "one" type relations, since applying them to an already single record makes no sense. If they're absent from "many" relations too, I'm going to need your schema to investigate the issue. As for filtering by values of relations, I'll see what I can do, currently my filters are duplicate of drizzle's RQB filters, and I'm not sure whether that would be possible to make with the way the drizzle rqb works.

@anthonyhoegberg
Copy link
Author

I see the offset thing was my miss, that's correct

However approaching the sort from the other end wouldn't work in my case since I'm filtering both the main object and the sub object so the issue persists there, could we add a specific custom filter for relational objects only maybe?

@Sukairo-02
Copy link
Collaborator

I did some investigation of current Drizzle RQB API, and conclusion is that it is impossible to implement this feature now.
Hovewer, that feature is planned to be added to drizzle, and once that's out - I'll add it to drizzle-graphql ASAP.

@anthonyhoegberg
Copy link
Author

Waiting for the relational API v2 would be the easiest way to tackle this problem
drizzle-team/drizzle-orm#2316

Right now would smth like this work as a hack?
drizzle-team/drizzle-orm#1152

@Sukairo-02
Copy link
Collaborator

While it could work, implementing this would be a nightmare and could quite possibly take me more time than it is left to wait for RQBv2

@anthonyhoegberg
Copy link
Author

anthonyhoegberg commented Aug 17, 2024

Could this possibly be done in the mean time with like a filter after getting the data from the database on the backend side? to simulate the new relational api until it comes out. I find myself working around a lot of issues to get it to work somewhat on the client side

@Sukairo-02
Copy link
Collaborator

You could actually reuse a type and add a wrapper around it's generated resolver with filters for that, but I don't really see a point of adding such functionality to the library right now as it does not get mapped to a DB query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants