best practice dynamic custom query in query all function based on inputs

I have an $input.type and what I do today is I create a function stack with if $input.type != null (in my screenshot I have input = all) then [query all with custom query db.type = input.type–, else [query all and no custom query]

Is there a smarter way to have only one query all and dynamically update my custom query based on the input I get? The result I am seeking is to turn the 3 rows below into 1

3 replies