
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeWhen working with blockContent (Portable Text) nested inside an array in Sanity with Gatsby, you're running into a common pattern where the _raw fields work differently than you might expect. Here's how to handle this:
The gatsby-source-sanity plugin generates _raw fields only for top-level document fields, not for fields nested within arrays or objects. As you've discovered, when you have blockContent inside an array, you won't get individual _rawFieldName fields for those nested items.
Instead of looking for _rawBlockContent on individual array items, you need to:
_raw field - For instance, if your array field is called sections, query _rawSectionsresolveReferences to expand any references within that raw dataHere's an example query structure:
query MyPageQuery {
sanityPage {
sections {
# Regular fields work fine here
_key
_type
}
# Access the raw blockContent through the parent array's _raw field
_rawSections(resolveReferences: {maxDepth: 5})
}
}In your component, you'd then access the blockContent like this:
const Page = ({ data }) => {
const { sections, _rawSections } = data.sanityPage
return (
<>
{_rawSections?.map((section, index) => {
// Now you have access to the full raw blockContent
if (section._type === 'textSection' && section.content) {
return (
<PortableText
key={section._key}
value={section.content} // This is your blockContent
/>
)
}
return null
})}
</>
)
}body will be mapped to _rawBody" - but this only applies to document-level fields, not nested onesresolveReferences parameter with maxDepth helps expand any referenced documents within your blockContent_raw version (like _rawSections for a sections array)_raw field, including all nested blockContentThis is the intended behavior of the plugin - raw fields are generated at the document root level to avoid excessive complexity in the GraphQL schema. By querying the parent array's _raw field, you get the complete nested structure including your blockContent elements.
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