Projections in GROQ are theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/gsinghjay/astro-shadcn-sanity/llms.txt
Use this file to discover all available pages before exploring further.
{ field1, field2, ... } clauses that select and transform fields from a document. This project defines two shared projection constants that are interpolated into every query that needs image or rich text data.
IMAGE_PROJECTION
Defined at the top of astro-app/src/lib/sanity.ts:
asset reference and pulls three sub-fields:
| Field | Type | Purpose |
|---|---|---|
asset._id | string | Sanity asset document ID, used by @sanity/image-url to construct the image URL |
asset.url | string | Direct CDN URL for the full-resolution image |
asset.metadata.lqip | string | Low-quality image placeholder (base64 data URI) for blur-up loading |
asset.metadata.dimensions | object | { width, height, aspectRatio } — enables native lazy loading with correct width/height attributes |
How it is used
Anywhere an image field appears in a query,IMAGE_PROJECTION is interpolated directly:
hotspot and crop fields are kept alongside the projection so @sanity/image-url’s urlFor() helper can apply editor-defined focal point cropping.
PORTABLE_TEXT_PROJECTION
Defined in astro-app/src/lib/sanity.ts:
portableText array in the queries. It uses GROQ’s conditional projection syntax (_type == "image" => { ... }) to:
- Spread all block fields (
...) — preserves_type,_key,style,children, and all other standard Portable Text fields. - Resolve inline images — when a block is of type
image, applyIMAGE_PROJECTIONplusaltandcaption. - Resolve internal links — within
markDefs, when a mark is of typeinternalLink, follow thereferencepointer and return_typeandslug.currentso the Portable Text renderer can build the correct href without a second query.
Where it is applied
PORTABLE_TEXT_PROJECTION is interpolated using array item syntax:
content array. It appears in:
PAGE_BY_SLUG_QUERY—textWithImage.content[],richText.content[],faqSection.items[].answer[]PROJECT_BY_SLUG_QUERY—content[]
The adapter pattern
Projections act as an adapter layer between Sanity’s document structure and component props. The flow is:Type-conditional projection syntax
ThePAGE_BY_SLUG_QUERY uses GROQ’s type-conditional projection to handle the heterogeneous blocks[] array. Each block type gets its own branch:
_type, _key, backgroundVariant, spacing, maxWidth, variant) are projected unconditionally. Block-specific fields are projected only when _type matches, keeping the result clean and the generated TypeScript union types precise.