gqlgen-sqlboiler
gqlgen-sqlboiler copied to clipboard
Apply a filter even if it is nil if it is explicitly specified in the GraphQL request
Not sure if this is the right place for the issue. So direct me if I'm wrong. But as the resolver is generated by gqlgen-sqlboiler
it might be the right spot.
Example below returns all fields from the database, but should return empty list
query {
deals(filter: {
where: {
creator: {
id: {
#equalTo: ""
}
}
}
}){
id
}
}
What happens if you uncomment Id and what happens if you set e.g. a non existing Id in it?
With an empty id it should return nothing, maybe we need to read the context from gqlgen like we do with update whitelist to check whether it is null or empty. Sometimes that difference is not there.
It is definitely something I want to fix with this library so it's the right place to ask this issue!
I'll try it out tomorrow with my own code do not have cases yet in my own programs submodel filtering but it should work!
If uncommented it returns an empty array
{
"errors": [
{
"message": "Could not list deals",
"path": [
"deals"
]
}
],
"data": null
}
When commented, generated SQL is quite descriptive
SELECT * FROM "deal";
What query do you want based on this
query {
deals(filter: {
where: {
creator: {
id: {
#equalTo: ""
}
}
}
}){
id
}
}
I think
SELECT * FROM "deal";
is the right output because we can't decide what exactly we want for a query.
Maybe we can agree that
id: {
equalTo: null
}
Should return the query like
SELECT * FROM "deal" where (creator_id = NULL);
The program does not yet understand the difference between explicit nil values in pointers. We fixed this in the update input so field which are set can be updated to nil values and fields which are not set will be ignored! See discussion here: https://github.com/99designs/gqlgen/issues/505
I can do the same for the filters as the update input so
id: {
equalTo: null
}
will be supported. Does this resolve your use-case?