I have the following GraphQL query (using Apollo Client JS):
query GetUsers($searchFilter: String) {
users(
first: 10,
filter: { search: $searchFilter }
) {
nodes {
id
name
}
}
}
This works well when I pass in the $searchFilter argument. However, I want this $searchFilter argument to be optional. So when it's null it doesn't apply the filter.
This seems simple enough, but the API requires the search to be non-nullable. So passing in filter: { search: null } is not allowed.
I would like to achieve the following:
query GetUsers($searchFilter: String) {
users(
first: 10,
filter: $searchFilter = null ? null : { search: $searchFilter }
) {
nodes {
id
name
}
}
}
How do I conditionally include the filter argument?