How to retrieve a list of all schemas from Sanity content lake?

1 replies
Last updated: Jun 11, 2023
Hey folks, another question but maybe more simple. Can I retrieve a list of all schemas I have on the content lake? I can't find a way to do that
AI Update

Yes! You can retrieve a list of all unique document types (_type values) from your Content Lake using GROQ. Here's how:

*[]._type

This 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.imageAsset and sanity.fileAsset if 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 thread
1 reply
Hi
user B
. The schemas don’t live on your Content Lake, so it won’t be possible to query for them. You can retrieve all the document and object `_type`s with the query
array::unique(*._type)
, but the schemas themselves will be found in your Studio codebase.

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.

Was this answer helpful?