
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe document passed to resolveProductionUrl doesn't include resolved references by default - you're absolutely right. You need to fetch the full document data yourself using Sanity's client within the resolveProductionUrl function.
The key is making resolveProductionUrl an async function and using a GROQ query with the reference operator (->) to dereference the category:
import { client } from './sanityClient' // Your configured client
export const resolveProductionUrl = async (doc) => {
if (doc._type !== 'article') return undefined
// Fetch the document with the resolved category reference
const article = await client.fetch(
`*[_id == $id][0]{
"categorySlug": category->slug.current,
"articleSlug": slug.current
}`,
{ id: doc._id }
)
if (!article?.categorySlug || !article?.articleSlug) return undefined
const baseUrl = 'https://your-site.com' // or process.env.NEXT_PUBLIC_SITE_URL
return `${baseUrl}/${article.categorySlug}/${article.articleSlug}`
}The category-> syntax in the GROQ query tells Sanity to resolve the reference and fetch the actual category document. Then category->slug.current gets the slug from that resolved document.
A few things to note:
_id: The doc parameter has the _id, which is stable and works even for drafts*[_id in [$id, "drafts." + $id]] to handle both published and draft versionsIf you're using the sanity-plugin-iframe-pane, the same approach works - just pass your async resolveProductionUrl function to the plugin's url option.
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