
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeLooking at the Structure Builder API, yes - you can query for the count and use it in your document list title! The context parameter passed to your structure function includes a getClient method that returns a configured Sanity client.
Here's how to make your title dynamic with the query count:
// sanity.config.js
import {structureTool} from 'sanity/structure'
export default defineConfig({
// ... other config
plugins: [
structureTool({
structure: async (S, context) => {
// Get a configured Sanity client from context
const client = context.getClient({apiVersion: '2023-01-01'})
// Fetch the count
const count = await client.fetch(
'count(*[_type == "property" && count(inspectionTimes) > 0])'
)
return S.list()
.title('Content')
.items([
S.documentList()
.schemaType('property')
.title(`${count} Properties with Inspection Times`)
.filter('_type == "property" && count(inspectionTimes) > 0')
])
}
})
]
})The key points from the Structure Builder API Reference:
context parameter includes several useful properties, including getClient - a callback function that returns a configured SanityClientawait query results before building your structurecontext.getClient() to get a client instance, optionally passing configuration like an API versionYou can also make this more reusable with a list item:
structure: async (S, context) => {
const client = context.getClient({apiVersion: '2023-01-01'})
const propertiesWithInspections = await client.fetch(
'count(*[_type == "property" && count(inspectionTimes) > 0])'
)
return S.list()
.title('Content')
.items([
S.listItem()
.title(`${propertiesWithInspections} Properties with Inspection Times`)
.child(
S.documentList()
.title(`${propertiesWithInspections} Properties with Inspection Times`)
.schemaType('property')
.filter('_type == "property" && count(inspectionTimes) > 0')
),
// ... other items
])
}Important notes:
apiVersion when calling getClient() for consistent behaviorSanity 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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store