Filter allUploads by collection

I’ve been poking around in the docs and the CDA playground but can’t seem to find a simple way to do this. Is it possible to filter allUploads by collection? The use case here is an image library where the client can just drop all the images they want into a collection to keep it easy to manage.

We could obviously use tags instead but the Collection feels like a more obvious and clean option. The Dato Admin is clearly able to filter on it using relationship but I don’t think this is documented in the CDA.

1 Like

Sorry @tim1,

I totally missed this last week! You’re right that there doesn’t seem to be a CDA filter for this yet. That might be an oversight; let me check with the devs on that.

In the meantime, you should be able to filter it using the CMA (just as a temporary workaround):

import {buildClient} from "@datocms/cma-client";

(async () => {
    const client = buildClient({apiToken: process.env.DATOCMS_API_TOKEN})

    const collectionId='YAYGIYV-TrOc-lds8ypQeQ';
    const filteredUploads = await client.uploads.list({
        filter: {
            collection_id: {
                eq: collectionId
            }
        }
    })
    console.log(filteredUploads)
    // returns array of uploads in that collection
})()

Sorry @tim1,

The devs confirmed that this is not currently in GraphQL, by design. I’ll turn this into a feature request for you (please vote for it at the top), but hopefully the CMA filter will work in the meantime. Sorry about that!

Thanks Roger!