web-ridge / gqlgen-sqlboiler

This is a plugin for gqlgen to generate converts + filter queries and resolvers for sqlboiler
MIT License
74 stars 13 forks source link

Apply a filter even if it is nil if it is explicitly specified in the GraphQL request #17

Open troian opened 4 years ago

troian commented 4 years ago

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
        }
}
RichardLindhout commented 4 years ago

What happens if you uncomment Id and what happens if you set e.g. a non existing Id in it?

RichardLindhout commented 4 years ago

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.

RichardLindhout commented 4 years ago

It is definitely something I want to fix with this library so it's the right place to ask this issue!

RichardLindhout commented 4 years ago

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!

troian commented 4 years ago

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";
RichardLindhout commented 4 years ago

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);
RichardLindhout commented 4 years ago

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

RichardLindhout commented 4 years ago

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?