Issue with getting data from an array in Sanity to Gatsby, but problem was resolved.
Looking at your schema setup, I can see the issue - you're using type: "document" for acccessibilityAuditCollection, but you're referencing it within an array field. This creates a mismatch in how Gatsby's GraphQL layer interprets the data.
When you have an array of documents in Sanity, you're essentially creating references to other documents, not embedding them directly. The gatsby-source-sanity plugin needs to understand whether you're embedding objects or referencing documents.
Here's what you need to fix:
Change your schema structure
You have two options:
Option 1: Use an object type instead of document (recommended for your use case)
Change acccessibilityAuditCollection from type: "document" to type: "object":
export default {
name: "acccessibilityAuditCollection",
title: "Accessibility audit product",
type: "object", // Changed from "document"
fields: [
{
name: "auditTitle",
title: "Title",
type: "string"
},
{
title: "Most sold product",
name: "released",
type: "boolean"
},
{
title: "Audit feature",
name: "smallAuditFeatures",
type: "array",
of: [{ type: "accessibilityAuditProductFeatures" }]
},
{
name: "auditButton",
title: "Audit level button text",
type: "string"
}
]
};Option 2: Use references if they need to be separate documents
If you want them to remain as separate documents (for reusability across multiple pages), change your array definition to use references:
{
title: "Audit levels",
name: "auditLevels",
type: "array",
of: [{
type: "reference",
to: [{ type: "acccessibilityAuditCollection" }]
}]
}After changing the schema
- Redeploy your GraphQL schema:
sanity graphql deploy - Clear Gatsby's cache:
gatsby clean - Restart your development server
Your GraphQL query should then work. If you used references (Option 2), your query would need to look slightly different to traverse the reference relationship.
The key insight here is that in Sanity, documents are top-level content types that live independently in your content lake, while objects are embedded data structures. For nested array data like you're describing, objects are typically the right choice unless you need to reuse the same audit collection across multiple pages.
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.