gatsby-source-sanity
gatsby-source-sanity copied to clipboard
Unable to access reference object properties on createSchemaCustomization
trafficstars
I'm trying to add a custom field to my SanityDocument by using createSchemaCustomization API, the new field will combine a few SanityDocument fields in one, but one of those fields is a reference field and on sanity GROQ it could be accessed like brand->name but on I don't know how to access it on createSchemaCustomization.
My createSchemaCustomization:
exports.createSchemaCustomization = ({ actions, schema }) => {
actions.createTypes([
schema.buildObjectType({
name: "SanityDocument",
interfaces: ["Node"],
fields: {
title: {
type: "String!",
resolve: (source) => {
console.log(source.brand)
return `${source.model} ${source.brand.name}`
}
},
},
}),
]);
};
This doesn't work, logging source.brand outputs
"brand":{
"_ref":"brand-36fef2ab-a5a0-472d-ac92-0f14cb9cae6b"
"_type":"reference"
}