How to retrieve a list of all schemas from Sanity content lake?
Yes! You can retrieve a list of all unique document types (_type values) from your Content Lake using GROQ. Here's how:
*[]._typeThis returns an array of all _type values from all documents. However, you'll likely want to get just the unique types without duplicates:
array::unique(*[]._type)This uses the array::unique() function to filter out duplicate _type values, giving you a clean list of all schema types that actually exist in your dataset.
Additional options
If you want more information about each type, you could count how many documents of each type exist:
{
"types": array::unique(*[]._type)
}Or create a more detailed breakdown by grouping and counting. While GROQ doesn't have a built-in GROUP BY, you can work around it:
array::unique(*[]._type) | order(@) {
"type": @,
"count": count(*[_type == ^])
}Where to run these queries
You can test these queries in:
- The Vision plugin in your Sanity Studio
- groq.dev playground
- Your application code using the Sanity client
- The HTTP API directly
Important notes
- This queries actual documents in your Content Lake, not your schema definition
- You'll only see types that have at least one document created
- If you've defined schemas but haven't created any documents of that type yet, they won't appear in the results
- This includes system document types like
sanity.imageAssetandsanity.fileAssetif you have uploaded assets
The array::unique() function is perfect for this use case - it removes duplicates from arrays, which is exactly what you need when getting all unique _type values from your documents!
Show original thread1 reply
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.