platformOS Community

Blank = everything?

Rich - DataOT Mar 05 2021 at 07:19

Why does POS return everything on a filter of "" ? shouldn't it return nothing or values without a name (if there were any)... shouldn't it be an empty result rather than everything?

For example:

query Users {
  users(per_page: 999, filter: {name: {value: ""}}) {
    results {
      name
      properties
    }
  }
}

will return everything in the database.... but if I do a query of (for example):

query Users2 {
  users(per_page: 999, filter: {name: {value: "r"}}) {
    results {
      name
      properties
    }
  }
}

it doesn't find anything because there is no name of just "r"

Darek Apr 02 2021 at 11:29

In platformOS all blank values in GraphQL filters have to be compatible with HTML forms. If you do not provide any value in the input, on server side you receive empty string, not null. This is why both { name: { value: ""} } and { value: null} are equivalent.

<form action="/form">
  <input name="keyword" type="text" value=""/>
  <input name="submit" type="submit" value="send"/>
</form>

when you submit this form without filling out the keyword field you will get context.params:

 {"keyword":"","submit":"send"} 

Using Javascript you get an empty string as well

document.querySelector("form input[name=keyword]").value // => ""

and we ignore these fields during graphql query executions - because that's the intuitive behaviour which most of users would expect

If you want to filter out items with an empty field you may try exists: false instead

Please sign in or fill up your profile to answer a question