drizzle-team / drizzle-graphql

Automatically generate GraphQL schema or customizable schema config fields from Drizzle ORM schema
https://www.npmjs.com/package/drizzle-graphql
Apache License 2.0
34 stars 1 forks source link

Add where filter for relational objects aswell? #13

Open anthonyhoegberg opened 2 weeks ago

anthonyhoegberg commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

Waiting for the relational API v2 would be the easiest way to tackle this problem https://github.com/drizzle-team/drizzle-orm/discussions/2316

Right now would smth like this work as a hack? https://github.com/drizzle-team/drizzle-orm/discussions/1152

Sukairo-02 commented 2 weeks ago

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