Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
troian opened this issue May 10, 2020 · 8 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@troian
Copy link

troian commented May 10, 2020

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
Copy link
Member

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

@RichardLindhout
Copy link
Member

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
Copy link
Member

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

@RichardLindhout
Copy link
Member

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
Copy link
Author

troian commented May 11, 2020

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
Copy link
Member

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
Copy link
Member

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: 99designs/gqlgen#505

@RichardLindhout
Copy link
Member

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 RichardLindhout self-assigned this May 11, 2020
@RichardLindhout RichardLindhout added enhancement New feature or request question Further information is requested labels May 11, 2020
@RichardLindhout RichardLindhout changed the title resolver returns all fields on empty query Apply a filter even if it is nil if it is explicitly specified in the GraphQL request May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants