Filtering collections

Filtering collections

Prepr automatically generates filters for the field types you add to your content models. You can apply these filters when fetching multiple content items. For that, include the where argument in your query, followed by the relevant filter types for the fields on your model. Check out the full list of the available filters below.

ID

Every content item in Prepr has it's own unique identifier _id that can be queried using the following filters:

argumenttypeBehaviour
_id_any[String]Query content items that match any of the giving ids
_id_nany[String]Query content items that match none of the giving id's

In this example we will query all the Posts that are listed in the _id_any argument.

query {
  Posts( where : { _id_any : [ "ff71321f-e2d6-4d4d-b62b-530d8fb92392", "ff71321f-e2d6-4d4d-b62b-530d8fb92392" ] } ) {
    items {
        _id,
        title
    }
  }
}

Slug

Prepr content item collections can be filtered on their slugs. For example to show a block like "More posts". You can query the Slug field by using the _slug_any or _slug_nany argument.

argumenttypeBehaviour
_slug_any[String]Query content items that match any of the giving slugs
_slug_any[]Query content items that have a slug
_slug_anyNULLQuery content items that don't have a slug
_slug_nany[String]Query content items that match none of the giving slugs

In this example we query all the Posts with the exception of the ones that are listed in the _slug_nany argument.

query {
  Posts( where : { _slug_nany : ["/posts/olympics-results-2022"] } ) {
	items {
    	_id
		_slug
	}
  }
}

Locales

You can specify a locale as an argument on all collection and single content types. If you don't specify a locale, the default locale of the environment is used. The locale argument cascades, meaning that all linked content items resolve with the locale as specified.

query {
  Posts( locale : "de-DE" ) {
    items {
        id,
        title
    }
  }
}

Check the Localization page for more on this.

String

String (Text) fields in your model can be filtered by using following filters:

argumenttypeBehaviour
field_nameStringEquals
field_name_containsStringIncluded in part of the string
field_name_not_containsStringNot included in part of the string
field_name_starts_withStringStarts with string
field_name_ends_withStringEnds with string
field_name_any[String]Matches is any of the giving strings equals the value

For example let's filter all authors where the name field starts with Mik.

query {
  Authors( where : { name_starts_with : "Mik" } ) {
    items {
        _id
    }
  }
}

Full-text search

You can use the _search argument to search for content items that contain a given text query. You can include this argument to query content items for a specific model or across multiple models. Check out the fetching multiple model collections reference for more info.

In the examples below, we query content items that mention "amsterdam" somewhere in a string field.

query {
  Posts( where: { _search : "amsterdam" } ) {
    items {
        id,
        title
    }
  }
}

Note The full text search is not case-sensitive.

Search options

Next to the _search argument, collections support an extra argument called _search_options. The SearchOptionInput contains two boolean fields includeReferences and includeNumeric to extend the search to all numeric content fields or referenced content items.

query {
    Posts( where : { _search : "amsterdam", _search_options : { includeReferences : true, includeNumeric : true  } }) {
        items {
            _id
        }
    }
}

Integer

Integer fields in your model can be filtered by using following filters:

argumenttypeBehaviour
field_nameIntegerEquals
field_name_gtIntegerGreater than
field_name_ltIntegerLess than
field_name_gteIntegerGreater than or equal to
field_name_lteIntegerLess than or equal to

For example let's filter all products where the rating field is 4 or higher.

query {
  Products( where : { rating_gt : 4 } ) {
    items {
        _id
    }
  }
}

Float

Float fields in your model can be filtered by using following filters:

argumenttypeBehaviour
field_nameFloatEquals
field_name_gtFloatGreater than
field_name_ltFloatLess than
field_name_gteFloatGreater than or equal to
field_name_lteFloatLess than or equal to

For example let's filter all products where the price field is 2.5 or higher.

query {
  Products( where : { price_gt : 2.5 } ) {
    items {
        _id
    }
  }
}

Boolean

Boolean fields in your model can be filtered by using their field name.

argumenttypeBehaviour
field_nameBooleanEquals

For example let's filter all products where the premium field is true.

query {
  Products( where : { premium : true } ) {
    items {
        _id
    }
  }
}

Simple Reference / Stack

All Content Reference or Stack fields that reference one model, can be filtered using filters on the fields of the model you are referencing.

argumenttypeBehaviour
field_name.whereWhereTypeWhere arguments for the referenced model
field_name.where{}Where the specified key has at least one item referenced
field_nameNULLWhere the specified field is empty

For example let's filter all Products where there is at least a Variant in the size small.

query {
  Products( where : { variants : { size : "small" } } ) {
    items {
        _id
    }
  }
}

Union Reference / Stack

All union Content Reference or Stack fields (reference fields that allow for multiple types) can be filtered using some specific filters.

argumenttypeBehaviour
field_name._id_any[String!]Query content items that have a reference matching any of the giving ids
field_name._id_nany[String!]Query content items that have a reference matching none of the giving id's
field_name._slug_any[String!]Query content items that have a reference matching any of the giving slugs
field_name._slug_nany[String!]Query content items that have a reference matching none of the giving slugs
field_name._typename_any[String!]Allows filtering content items that have a reference matching on of the given types
field_name._slug_nanyNULLWhere the specified field contains no references

For Stack fields, the filters apply only to referenced content items. Since version 2024-12-05, the _typename_any filter also applies to referenced component types.

An example let's filter all Product where the parent page is a category.

query {
  Products( where : { parent : { _typename_any : ["Category"] } } ) {
    items {
        _id
    }
  }
}

Date

Date fields in your model can be filtered by using following filters:

argumenttypeBehaviour
field_nameStringEquals
field_name_gtStringGreater than
field_name_ltStringLess than
field_name_gteStringGreater than or equal to
field_name_lteStringLess than or equal to

For example let's filter all events on 1 September 2022. Dates in Prepr are saved in UTC Strings (ISO 8601).

query {
  Events( where : { date : "2022-09-01" } ) {
    items {
        _id
    }
  }
}

Date Range

Date range fields in your model can be filtered by using following filters:

argumenttypeBehaviour
field_name{from_gt}StringGreater than
field_name{from_gte}StringGreater than or equal to
field_name{from_lt}StringLess than
field_name{from_lte}StringLess than or equal to
field_name{until_gt}StringGreater than
field_name{until_gte}StringGreater than or equal to
field_name{until_lt}StringLess than
field_name{until_lte}StringLess than or equal to

For example let's filter all events after 28th August 2022. Dates in Prepr are saved in UTC Strings (ISO 8601).

query {
  Events( where : { "event_dates": { "from_gte": "2022-08-28" } } ) {
    items {
        _id
    }
  }
}

DateTime

DateTime fields in your model and the system fields _publish_on, _created_on and _changed_on can be filtered by using following filters:

argumenttypeBehaviour
field_nameStringEquals
field_name_gtStringGreater than
field_name_ltStringLess than
field_name_gteStringGreater than or equal to
field_name_lteStringLess than or equal to

For example let's filter all events after 1 October 2022. Dates in Prepr are saved in UTC Strings (ISO 8601).

query {
  Events( where : { date_gt : "2022-10-01T08:00:00+00:00" } ) {
    items {
        _id
    }
  }
}

DateTime Range

DateTime range fields in your model can be filtered by using following filters:

argumenttypeBehaviour
field_name{from_gt}StringGreater than
field_name{from_gte}StringGreater than or equal to
field_name{from_lt}StringLess than
field_name{from_lte}StringLess than or equal to
field_name{until_gt}StringGreater than
field_name{until_gte}StringGreater than or equal to
field_name{until_lt}StringLess than
field_name{until_lte}StringLess than or equal to

For example let's filter all events after 28th August 2022. Dates in Prepr are saved in UTC Strings (ISO 8601).

query {
  Events( where : { "event_dates": { "from_gte": "2022-08-20T00:00:00+00:00" } } ) {
    items {
        _id
    }
  }
}

Remote Content

Remote content fields in your model can be filtered by the ID used in the Remote Source.

argumenttypeBehaviour
field_name{_id_any}[String]Matches items referencing one of the specified ID's

For example let's filter all Category pages where our product is mentioned.

query {
  ProductCategories( where : { products : {
                _id_any : [
                    "2387hasdkury3287h376s-23483268"
                ]
            }
        }) {
    items {
        _id
        title
    }
  }
}

Business hours

Business hours fields in your model can be filtered by using following filters:

argumenttypeBehaviour
field_name{open_day_in}[DayOfWeek!]Open on one of the given days
field_name{open_on_in}[_Date!]Open on one of the given dates

For example let's filter all locations open on Monday.

query {
  Locations( where : { "business_hours": { "open_day_in": [ MONDAY, FRIDAY ] } } ) {
    items {
        _id
    }
  }
}

List

List fields in your model can be filtered by using following filters:

argumenttypeBehaviour
field_nameStringEquals
field_name_containsStringIncluded in part of the string
field_name_any[String]Equals one of the given strings
field_name_starts_withStringStarts with string
field_name_ends_withStringEnds with string

For example let's filter all Products where the color field is red or blue.

query {
  Products( where : { color_any : ["red", "blue"] } ) {
    items {
        _id
    }
  }
}

Location

Location fields in your model can be filtered by using following filters:

argumenttypeBehaviour
field_name_within_circleArrayArray containing the following arguments
field_name_within_circle.latFloat-
field_name_within_circle.lonFloat-
field_name_within_circle.radiusIntDistance in kilometers

For example let's filter all Events within 10 kilometers of Amsterdam.

query {
  Events( where : { location_within_circle : {
            lat : 40.730610,
            lon : -73.935242,
            radius: 10
            }
        }) {
    items {
        _id
        location {
            latitude
            longitude
        }
    }
  }
}

Tags

Tag fields in your model can be filtered by using following filters:

argumenttypeBehaviour
field_name_any[String]Equals any of the given tags (or)
field_name_all[String]Equals all of the given tags (and)
field_name_nany[String]Equals none of the given tags
field_name_hasBooleanIncludes at least one tag

The example below filters all Nobel prize winning authors with the prize tag and a value of Nobel.

query {
  Authors( where : { prize_any : "Nobel" } ) {
    items {
        _id
    }
  }
}

You can also filter by the slug of a tag instead of the actual value. The example below filters all Nobel prize winning authors with the prize tag and a slug of nobel.

query {
  Authors( where : { prize_any : ["slug:nobel"] } ) {
    items {
        _id
    }
  }
}

Deprecated Tag Filters

You can query tag fields using the _tags_any, _tags_all, _tags_has, _tags_nany arguments. These filters work on all tags referenced in a content item, not restricted by a field name.

argumenttypeBehaviour
_tags_any[String]Equals any of the given tags (or)
_tags_all[String]Equals all of the given tags (and)
_tags_nany[String]Includes at least one tag
_tags_hasBooleanEquals none of the given tags

Customer content relation

The engagement your customers have with your content items can be tracked using the Prepr Tracking Code. If customers are allowed to bookmark, subscribe or like content items, this filter allows you to make a collection of the content items the customer has for example liked.

This filter is available on the Multi Type collection query.

For example, we query all posts items bookmarked by the specified customer.

query {
    ContentItems(
        where: {
            _typename_any : ["Post"]
            _customer_relation : {
                id : "ad5714b0-dea5-46b3-9386-0f109ebbe29b",
                event : Bookmark
            }
        }
    ) {
        items {
            ... on Post {
                name
            }
        }
    }
}

Next to the Prepr Customer ID, querying using the customer's Reference ID is also possible.

query {
    ContentItems(
        where: {
            _typename_any : ["Post"]
            _customer_relation : {
                reference_id : "ad5714b0-dea5-46b3-9386-0f109ebbe29b",
                event : Bookmark
            }
        }
    ) {
        items {
            ... on Post {
                name
            }
        }
    }
}

New Event types created in the tracking API will be available are a few hours.

Please be aware that caching is done based on the query, for every customer this will be considered a new request and will have an impact on response times. Consider keeping this query simple and use a follow-up query to fetch deep nested content.

Environment ID filter

If you are using the GraphQL API with a multi-environment token you can filter content items on the environment they are created in.

argumenttypeBehaviour
_environment_id_any[String]Qeury content items from environments with the specified IDs

In this example we query all Posts that are created in any of the environments listed in the __environment_id_any argument.

query {
  Posts( where : { _environment_id_any : [ "ff71321f-e2d6-4d4d-b62b-530d8fb92392", "ff71321f-e2d6-4d4d-b62b-530d8fb92392" ] } ) {
    items {
        _id,
        _environment_id
        title
    }
  }
}

Combining filters

It's also possible to combine different filters. This example shows how to do that.

query {
  Products( where : {
              variants : { size : "small" }
              premium: true,
              rating_gt: 4
        } ) {
    items {
        _id
    }
  }
}

Conditional filters

Conditional filters allow you to filter results based on sets of criteria. In this example, we filter all items that have a boolean field set to true or have a high rating:

query {
  Products( where : { _or : [ { boost: true }, { rating_gt: 4.5 } ] } )
    {
        items {
        _id
    }
  }
}

Channels (deprecated)

This feature is deprecated With Prepr you can publish to all your digital channels. Publish to your website, app, live blog, social wall, social media and on location screens. All those different front-ends can be defined as a Channel.

argumenttypeBehaviour
_channels_any[String]Query content items within a channel

Was this article helpful?

We’d love to learn from your feedback