Get field title property with GROQ query
I think there might be some confusion here about what GROQ queries can access. GROQ queries operate on your content (the actual documents in your dataset), not on your schema definitions. This means you can't use GROQ to return schema-level metadata like a field's title property from your schema definition.
Here's what I mean:
What GROQ CAN do:
Query the actual content values in your documents. For example, if you have a document with a title field:
*[_type == "post"] {
title,
description
}This returns the content of those fields (like "My Blog Post"), not the schema metadata (like the field's title property you defined as "Post Title").
What GROQ CANNOT do:
Access schema definitions, field configurations, or metadata like:
- Field
titleproperties - Field
descriptiontext - Validation rules
- Field types
- Other schema-level configurations
Why this limitation exists:
GROQ is designed as a query language for your Content Lake - the actual documents and their values. Your schema exists separately as configuration code that defines the structure of your content, but it's not stored as queryable data in the Content Lake.
Alternative approaches:
If you need to access schema metadata in your application, you could:
- Import your schema directly in your frontend code and read the field definitions from there
- Create a separate content type that mirrors your schema metadata if you need it to be editable/queryable
- Use the Sanity CLI to extract schema information programmatically during build time
The key distinction is: GROQ queries your data (document content), not your schema (field configuration). The schema defines what fields can exist and how they're structured, while GROQ retrieves what values actually exist in your documents.
Show original thread24 replies
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.