gqlgen-sqlboiler icon indicating copy to clipboard operation
gqlgen-sqlboiler copied to clipboard

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

Open troian opened this issue 4 years ago • 8 comments

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
        }
}

troian avatar May 10 '20 18:05 troian

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

RichardLindhout avatar May 10 '20 20:05 RichardLindhout

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 avatar May 10 '20 20:05 RichardLindhout

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

RichardLindhout avatar May 10 '20 20:05 RichardLindhout

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!

RichardLindhout avatar May 10 '20 20:05 RichardLindhout

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";

troian avatar May 11 '20 00:05 troian

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 avatar May 11 '20 09:05 RichardLindhout

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 avatar May 11 '20 09:05 RichardLindhout

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?

RichardLindhout avatar May 11 '20 09:05 RichardLindhout