> ## Documentation Index
> Fetch the complete documentation index at: https://docs.withchanneled.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Filtering

You can filter the results of any query by using the `filter` argument. This makes it easy to retrieve specific information, like any threads assigned to a particular user, but much more complex queries are also possible.

For example, to return all open threads that are assigned to a particular user, you can use the following query:

```graphql theme={null}
query {
  threads(filters: [
    {
      "field": "status",
      "operation": "IN",
      "value": ["New", "Open", "Escalated", "Waiting for Customer"]
    },
    {
      "field": "ownerId",
      "operation": "EQUALS",
      "value": "1"
    }
  ]) {
    id
    body
    status
    owner {
      id
      name
    }
  }
}
```

## Operations

You can use the following operations to filter your results:

| Operation             | Description                                                     | Type              |
| --------------------- | --------------------------------------------------------------- | ----------------- |
| `BETWEEN`             | Between two given values.                                       | \[string, string] |
| `IN`                  | One of the given values.                                        | string\[]         |
| `NOT_IN`              | Not one of the given values.                                    | string\[]         |
| `EQUALS`              | Equal to given value.                                           | \[string]         |
| `NOT_EQUALS`          | Not equal to given value.                                       | \[string]         |
| `GREATER`             | Greater than given value.                                       | \[string]         |
| `LESS`                | Less than given value.                                          | \[string]         |
| `GREATER_EQUALS`      | Greater than or equal to given value.                           | \[string]         |
| `LESS_EQUALS`         | Less than or equal to given value.                              | \[string]         |
| `LIKE`                | Like given value. (Accepts the `%` operator)                    | \[string]         |
| `NOT_LIKE`            | Not like given value. (Accepts the `%` operator)                | \[string]         |
| `ILIKE`               | Like given value, ignoring case. (Accepts the `%` operator)     | \[string]         |
| `NOT_ILIKE`           | Not like given value, ignoring case. (Accepts the `%` operator) | \[string]         |
| `CONTAINS`            | Contains given value.                                           | \[string]         |
| `NOT_CONTAINS`        | Not contains given value.                                       | \[string]         |
| `ICONTAINS`           | Contains given value, ignoring case.                            | \[string]         |
| `NOT_ICONTAINS`       | Not contains given value, ignoring case.                        | \[string]         |
| `STARTS_WITH`         | Starts with given value.                                        | \[string]         |
| `DOES_NOT_START_WITH` | Not starts with given value.                                    | \[string]         |
| `ARRAY_CONTAINS`      | Array contains given value.                                     | \[string]         |
| `NULL`                | The value of the field must be null.                            | \[]               |
| `NOT_NULL`            | The value of the field must not be null.                        | \[]               |
| `ARRAY_EMPTY`         | Array is empty.                                                 | \[]               |
| `ARRAY_NOT_EMPTY`     | Array is not empty.                                             | \[]               |

## Logical operators

By defailt, all fields described in the filter need to be matched. The filter merges all conditions together using a logical **and** operator.

For example, the below example will find all threads that were created before a specific timeframe and are assigned to a particular user.

```graphql theme={null}
query {
  threads(filters: [
    {
      "field": "createdAt",
      "operation": "LESS",
      "value": "2024-05-31T16:34:11.909Z" # ISO 8601 Format
    },
    {
      "field": "ownerId",
      "operation": "EQUALS",
      "value": "1"
    }
  ]) {
    id
    body
    createdAt
    owner {
      id
      name
    }
  }
}
```

To change the logical operator, all filters support the `or` keyword that lets you switch to a logical **or** operator. For example, to find all threads that were created before a specific timeframe or are assigned to a particular user, you can use the following query:

```graphql theme={null}
query {
  threads(filters: [
    {
      "field": "createdAt",
      "operation": "LESS",
      "value": "2024-05-31T16:34:11.909Z" # ISO 8601 Format
      "or": [
        {
          "field": "ownerId",
          "operation": "EQUALS",
          "value": "1"
        }
      ]
    }
  ]) {
    id
    body
    createdAt
    owner {
      id
      name
    }
  }
}
```

## Filtering by relationship

Data can also be filtered based on their relations, For example, you can filter threads based on the properties of their owner. To query all threads assigned to a particular email address, you can use the following query:

```graphql theme={null}
query {
  threads(filters: [
    {
      "field": "owner.email",
      "operation": "EQUALS",
      "value": "john@withchanneled.com"
    }
  ]) {
    id
    body
    owner {
      id
      name
      email
    }
  }
}
```
