Collections filtering

In addition to entity properties, you can apply filtering on collections that are in relation with those entities, with the following operators:

Operators

Name Type Description

any

Depends on the collection

Any of the collection items matches the given expression.

all

Depends on the collection

Every collection item matches the given expression.

none

Depends on the collection

None of the collection items matches the given expression.

empty

Boolean

The target collection is empty.

typePublicId

String

Only available for the typed collections, such as asset attributes or relations. Allows you to filter collection elements by the public ID of the element type.

You can only use one of the any, all, none, and empty operators in the same collection filter expression.

The any operator

This filtering operator means that any of the related entities fulfill the given criteria. The following example is a query for all assets with a stringAttribute that contains the word personal and is created by user with first name Admin:

query {
    assets(
        where: {
            stringAttributes: {
                any: {_and: [
                    {stringValue: {contains: "Personal"}}
                    {createdBy: {firstName: {eq: "Admin"}}}
                ]}}
        }
    ) {
        id
        fullName
        stringAttributes {
            stringValue
            createdBy {
                firstName
            }
        }
    }
}

The response contains all assets that have a string attribute containing the word personal and created by a user with first name Admin but all of the other string attributes are returned. To further narrow down the results and only get the descriptions, add another filter on the inner stringAttributes field:

query {
    assets(
        where: {
            stringAttributes: {any: {_and: [
                {stringValue: {contains: "Personal"}}
                {createdBy: {firstName: {eq: "Admin"}}}
            ]}}
        }
    ) {
        id
        fullName
        stringAttributes(where: {createdBy: {firstName: {eq: "Admin"}}}) {
            stringValue
            createdBy {
                firstName
            }
        }
    }
}

The all operator

This filtering operator means that every entity fulfills the given criteria. The following example is a query for domains where all of the assets have the status Accepted:

query {
    domains(
        where: { assets: { all: { status: { name: { eq: "Accepted" } } } } }
    ) {
        id
        assets {
            fullName
            status {
                name
            }
        }
    }
}

The none operator

This filtering operator means that none of the entities fulfills the given criteria. This example demonstrates how to query the opposite of the all query example, domains where none of their assets have the status Accepted:

query {
    domains(
        where: { assets: { none: { status: { name: { eq: "Accepted" } } } } }
    ) {
        id
        assets {
            fullName
            status {
                name
            }
        }
    }
}

The difference between using { all: { status: { name: { ne: "Accepted" } } } } and { none: { status: { name: { eq: "Accepted" } } } } is that for the none condition, the response contains domains where there are no assets or there are assets with no status set.

The empty operator

This operator specifies that a given collection is empty. The following example is a query for all of the assets that don't have any dateAttributes assigned:

query {
    assets(where: { dateAttributes: { empty: true } }) {
        id
        fullName
        dateAttributes {
            type {
                name
            }
            dateValue
        }
    }
}

The typePublicId operator

This filtering operator restricts the next filtering condition to only apply on a given type of relation. It is the equivalent of { type: { publicId: { eq: "someValue" } } }.

You can add the filter in a collection filter using the implicit AND. The following example returns assets that don't have any stringAttributes that have a publicId equal to Note:

query {
    assets(where: { stringAttributes: { typePublicId: "Note", empty: true } }) {
        id
        fullName
        stringAttributes(where: { type: { publicId: { eq: "Note" } } }) {
            stringValue
            type {
                name
            }
        }
    }
}

In all of the above examples the query fetches the fields you are filtering on even though this is not necessary. If you don't need to verify the results, the above query is going to return the same asset data when omitting fetching the stringAttributes:

query {
    assets(where: { stringAttributes: { typePublicId: "Note", empty: true } }) {
        id
        fullName
    }
}