I have a table with firstName
and lastName
. I want to have a GraphQL query to filter by these two fields individually (only first or last name, or first and last name combined).
This is the query I have so far:
query MyQuery($value: String!) {
personsList(
filter: {
OR: [
{ firstName: { contains: $value } }
{ lastName: { contains: $value } }
]
}
) {
items {
id
firstName
lastName
}
}
}
When passing "John"
or "Smith"
as the value
, the query returns the record, but passing "John Smith"
obviously doesn’t work because neither firstName
or lastName
contain the whole name. Is there a filter that’s the opposite of contains
? Instead of having the data in the field contain the value
, I need the value
to contain the data in the field.
I couldn’t find anything in the docs for filtering, so I’d appreciate some help if I’m missing something obvious, or would love to know if that’s a known limitation of filtering.
The only solution I can think of right now is to split the value
based on spaces in the string and use the in
filter, but that doesn’t seem ideal.