Filtering
The where argument can be used in queries to filter results based on some field's values. Multiple filters can be used in the same where clause using the _and or the _or operators and can also be used to filter nested relationships, as the following examples demonstrate.
Equality operators
_eq, _neq
The _eq (equal to) or the _neq (not equal to) operators are compatible with any database type, e.g. Boolean, Text, Integer, Float, Double, Date, etc. The following example uses the _eq operator to filter on the nested relation Person, looking for all patients whose first name equals "Priscilla"
{
patients(where: { person: { firstName: { _eq: "Priscilla" } } }) {
person {
id
firstName
lastName
birthDate
}
}
}The
_eqor_neqoperators will not return rows with null values. To also return rows with null values, the_isNull_operator needs to be used along with these joined by the_oroperator.
Greater than or less than operators
_gt, _lt, _gte, _lte
The _gt (greater than), _lt (less than), _gte (greater than or equal to), _lte (less than or equal to) operators are compatible with any database type, e.g. Boolean, Text, Integer, Float, Double, Date, etc.
The following example gets all patients whose date of birth is greater than or equal to January 1st 2015.
query docs_patients {
patients(where: { person: { birthDate: { _gte: "2015-01-01" } } }) {
person {
firstName
lastName
gender
birthDate
}
}
}List based search operators
(_in, _nin)
The _in (in a list) and _nin (not in list) operators are used to compare field values to a list of values.
The following example gets all patients whose date of birth is greater than or equal to January 1st 2015.
{
patients(where: { person: { firstName: { _in: ["Mary"] } } }) {
person {
firstName
lastName
gender
birthDate
}
}
}Search filter using text values
_like, _nlike, _ilike, _nilike, _similar, _nsimilar, _regex, _nregex, _iregex, _niregex
_like
Fetches objects (case sensitive) where a text field contains the string, e.g. patients whose first name is contains "irley".
{
patients(where: { person: { firstName: { _like: "%irley%" } } }) {
person {
firstName
lastName
gender
birthDate
}
}
} _nlike
Fetches objects (case sensitive) where a text field does not contains the string, e.g. patients whose first name does not contains "irley".
{
patients(where: { person: { firstName: { _nlike: "%irley%" } } }) {
person {
firstName
lastName
birthDate
gender
}
}
} _ilike
Fetches objects where a text field contains the string, regardless of case, e.g. patients whose first name does not contains "iRLey".
{
patients(where: { person: { firstName: { _ilike: "%irley%" } } }) {
person {
firstName
lastName
birthDate
gender
}
}
} _similar
This is case sensitive. An example - patients whose first name begins with either L, M or O.
{
patients(where: { person: { firstName: { _similar: "(L|M|O)%" } } }) {
person {
firstName
lastName
birthDate
gender
}
}
}