
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeLooking at your query, I can see the issue with how you're trying to resolve internal link references in your Portable Text content. The problem is in the structure of your projection - you have an unnecessary nested check that's preventing proper dereferencing.
Here's the corrected query:
*[_type == "page" && slug == "what-is-veterinary-physiotherapy"]{
...,
content[]{
...,
markDefs[]{
...,
_type == "internalLink" => {
"slug": @.reference->slug
}
}
}
}What changed:
_type == "reference" check - this was causing the issue@.reference->slug to properly dereferenceHow it works:
@ symbol refers to the current element in the markDefs array (your internalLink object).reference-> follows the reference field using GROQ's dereference operator (->)slug grabs the slug field from the referenced documentImportant note: If your slug is stored as an object with a current property (which is common in Sanity), you'll need:
*[_type == "page" && slug == "what-is-veterinary-physiotherapy"]{
...,
content[]{
...,
markDefs[]{
...,
_type == "internalLink" => {
"slug": @.reference->slug.current
}
}
}
}This pattern is documented in Sanity's guide on joining references in Portable Text. The arrow operator (->) is the key to dereferencing and fetching data from related documents in GROQ queries.
If you need to fetch additional fields from the referenced document (like title, or the entire slug object), you can expand the projection:
markDefs[]{
...,
_type == "internalLink" => {
"slug": @.reference->slug.current,
"title": @.reference->title
}
}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.
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