# Filtering

## Overview

ViewConnection queries support collection-specific filters to narrow down results. Filters vary by collection based on the data model.

## Filter Types

### Simple Value Filters

Filter by exact value or list of values:

```graphql
query {
  orderViewConnection(
    first: 10
    type: ["SALES_ORDER", "RETURN_ORDER"]
  ) {
    edges {
      node {
        orderId
        type
      }
    }
  }
}
```

### Date Range Filters

Filter by date ranges:

```graphql
query {
  orderViewConnection(
    first: 10
    orderDate: { start: "2024-01-01", end: "2024-12-31" }
  ) {
    edges {
      node {
        orderId
        orderDate
      }
    }
  }
}
```

### Number Range Filters

Filter by numeric ranges:

```graphql
query {
  productViewConnection(
    first: 10
    quantityOnHand: { start: 0, end: 100 }
  ) {
    edges {
      node {
        productId
        quantityOnHand
      }
    }
  }
}
```

### Sequence Number Filters

Filter by ID sequences:

```graphql
query {
  orderViewConnection(
    first: 10
    sequence: { start: 1000, end: 2000 }
  ) {
    edges {
      node {
        orderId
        sequence
      }
    }
  }
}
```

## Combining Multiple Filters

Filters can be combined in a single query:

```graphql
query {
  orderViewConnection(
    first: 10
    type: ["SALES_ORDER"]
    status: ["OPEN", "IN_PROGRESS"]
    orderDate: { start: "2024-01-01", end: "2024-12-31" }
  ) {
    edges {
      node {
        orderId
        type
        status
        orderDate
      }
    }
  }
}
```

## Filter Behavior

- Multiple values in a filter are treated as OR (e.g., `type: ["SALES_ORDER", "RETURN_ORDER"]`)
- Multiple different filters are treated as AND (e.g., `type` AND `status`)
- Empty or null filter values are ignored

## Discovering Available Filters

Each collection has different available filters. To find filters for a collection:

1. Check the collection's reference page (e.g., `reference/order.md`)
2. Use GraphQL introspection to query the schema
3. Query the `dataSetMeta` endpoint (advanced usage)

## Filter Option Lists

Some filters have predefined valid values. These are documented in the reference pages for each collection.

**Example:** Order status filter might accept:

- `OPEN`
- `IN_PROGRESS`
- `COMPLETED`
- `CANCELLED`

## Dynamic Filter Options

Some filter options vary by account based on:

- Custom fields defined for your account
- Integration-specific fields
- Location-specific settings

Use the reference documentation to identify which filters have fixed vs. dynamic option lists.
