Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Resolving references in Sanity.io preview content on site

4 replies
Last updated: Jun 8, 2020
One more question! I have a preview thingie based on this: https://www.sanity.io/docs/preview-content-on-site Now I want to consult a field on a reference (e.g.
document.property->nestedPoperty
), but the object passed in just contains the reference. How can I resolve the reference in this context?
May 11, 2020, 8:22 PM
I think you will need to query that data async, using the client.
something along the lines of:

import client from 'part:@sanity/base/client'

export default async function resolveProductionUrl(document) {

  const referencedDoc = await client.getDocument(document.property._ ref)

  return `<https://my-site.com/posts/${referencedDoc.property}>`
}
May 11, 2020, 8:30 PM
Perfect, thanks again!
May 11, 2020, 9:03 PM
Perfect, thanks again!
May 11, 2020, 9:03 PM
Does this actually work? https://github.com/sanity-io/sanity/issues/1374 and sanity ticket 827
Jun 8, 2020, 9:27 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?