Filtering

Filtering allows you to query your content for items which match a set of parameters. You can define these parameters by passing the filter argument to your query.

Basic Filtering

The available filter options will depend on the fields that were defined within the content type that is being filtered and the types of those fields. Each field type supports a different set of filters.

Supplying just one filter will only return items which match the specified constraint. For example, the below query will only return books which have a title that equals “My Awesome Book”.

query {
  bookCollection(filter: {
    title: { _eq: "My Awesome Book" }
  }) {
    items {
      title
      publishedDate
    }
  }
}

If you specify multiple filters, they will be combined using an AND expression. Extending the above example, the following query will only return books that were also published after 1st January 2020.

query {
  bookCollection(filter: {
    title: { _eq: "My Awesome Book" }
    publishedDate: { _gt: "2020-01-01" }
  }) {
    items {
      title
      publishedDate
    }
  }
}

AND / OR

You can also go further and provide the special _AND and _OR filters which allow to create more complicated filter expressions.

The below example uses the _OR filter and will only return books which were published after 1st January 2020 but were also given a 5 star rating or are in the “Techology” genre.

query {
  bookCollection(filter: {
    publishedDate: { _gt: "2020-01-01" }
    _OR: [
      { rating: { _eq: 5 } }
      { genre: { _eq: "Technology" } }
    ]
  }) {
    items {
      title
      publishedDate
    }
  }
}

Available Filters for Field Types

As mentioned earlier, the types of filters that are available depends on the fields and the types of those fields that are defined within the content model for the content type being filtered.

This section will cover the list of available filters for each possible field type.

Boolean

Filter for records that have the specified field populated or not.
query {
  bookCollection(filter: {
    booleanField: { _exists: true }
  }) {
    # ...
  }
}

Date/Time

Filter for records that have the specified field populated or not.

query {
  bookCollection(filter: {
    dateTimeField: { _exists: true }
  }) {
    # ...
  }
}

Decimal

Filter for records that have the specified field populated or not.
query {
  bookCollection(filter: {
    decimalField: { _exists: true }
  }) {
    # ...
  }
}

Image

Image fields do not currently support filtering, though it will be coming in a future release.

Integer

Filter for records that have the specified field populated or not.
query {
  bookCollection(filter: {
    integerField: { _exists: true }
  }) {
    # ...
  }
}

Markdown

Filter for records that have the specified field populated or not.
query {
  bookCollection(filter: {
    markdownField: { _exists: true }
  }) {
    # ...
  }
}

Relationship

Relationship fields do not currently support filtering, though it will be coming in a future release.

Select (Dropdown)

Filter for records that have the specified field populated or not.
query {
  bookCollection(filter: {
    selectField: { _exists: true }
  }) {
    # ...
  }
}

Text (Single Line)

Filter for records that have the specified field populated or not.
query {
  bookCollection(filter: {
    textSingleField: { _exists: true }
  }) {
    # ...
  }
}

Text (Multi Line)

Filter for records that have the specified field populated or not.
query {
  bookCollection(filter: {
    textMultiField: { _exists: true }
  }) {
    # ...
  }
}

© 2020 Status200 Ltd.