graphjin
graphjin copied to clipboard
Complex Relational Filters?
This project looks awesome. I'm somewhat of a noobie to GraphQL and still finding my feet.
One question I had that I cant seem to find in the docs is more complex RoleTable configurations. All filters in the docs point to simple relational data if I am not mistaken.
Products that have user_id
foreign keys on the table themselves in this case.
Is there a mechanism to support more complex filtering? For example my db is structured as follows:
data |
---|
data |
organisation_id (FK to organisation) |
organisation |
---|
id |
name |
user_organisation |
---|
user_id (FK to user) |
organisation_id (FK to organisation) |
user |
---|
id |
name |
So in my case the filter is twice removed from the table itself in the case of data
the filter would need to be something like ["{ organisation.user: { eq: $user_id } }"]
. Which obviously wont work.
I had also thought of using the hardcoded Vars
and then doing an in
filter based on data.organisation_id
. Which is a static list of all the users organisation ids? I couldnt get this to work though.
Effectively what I would like is to be able to provide all users with read access to their own data. Apologies if this is obvious and I am missing something here but I can't work out if this is possible.
If it is then excellent! Thanks for any help in advance
Looks like perhaps there is support for this? https://github.com/dosco/graphjin/blob/d13b266039952314c592c9a6284ab48e8a27f8e2/core/internal/qcode/qcode.go#L1498
I'm more than happy to document this if someone can point me in the right direction 😄
So I'm starting to realise that my question is perhaps a little silly.
Are these filters syntactically identical to GrapQL filters?
If so I think the answer to my question is the filter should be:
["{ organisation: { user: { id: { eq: $user_id } } }"]
I'm not at my computer at the moment but I think this might work?? 😅 I'll try this tomorrow
Yup, this is the right way to write those filters. You can find several more examples in the godocs https://pkg.go.dev/github.com/dosco/[email protected]/core
Thanks @dosco apologies if I am mistaken but I dont think there are any examples of complex filters such as this in the examples? Indeed there isn't a single example of use of a Filter in the Go package docs. There is the simple one I mentioned above in the GitHub wiki.