Get field title property with GROQ query

24 replies
Last updated: Nov 29, 2025
Hello! I am wondering if it is possible to create a GROQ query that returns the title property of a field?
AI Update

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 title properties
  • Field description text
  • 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:

  1. Import your schema directly in your frontend code and read the field definitions from there
  2. Create a separate content type that mirrors your schema metadata if you need it to be editable/queryable
  3. 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 thread
24 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.

Was this answer helpful?