Anyone who could help me out with sanity/mux?
You're hitting a common issue when working with Mux videos in Sanity! The problem is that your basic GROQ query only returns the reference to the video asset, not the actual asset data containing the playbackId and other Mux information you need.
The Solution: Dereference the Asset
You need to dereference the video asset in your GROQ query using the -> operator. Change your query from:
*[_type == "post"]to:
*[_type == "post"] {
...,
video {
asset->
}
}The -> operator tells GROQ to follow the reference and fetch the actual mux.videoAsset document instead of just returning { _ref: '...' }.
Getting the Playback ID and Asset ID
Once you dereference the asset, you can access fields like playbackId, assetId, and more. Here's a more complete query example from the official Mux plugin documentation:
*[_type == "post"] {
...,
video {
asset-> {
_id,
playbackId,
assetId,
status,
filename,
thumbTime
}
}
}This will return data like:
{
video: {
asset: {
_id: '4e37284e-cec2-406d-973c-fdf9ab1e5598',
playbackId: 'YA02HBpY02fKWHDRMNilo301pdH02LY3k9HTcK43ItGJLWA',
assetId: '7ovyI76F92n02H00mWP7lOCZMIU00N4iysDiQDNppX026HY',
status: 'ready',
filename: 'my-video.mp4'
}
}
}Understanding the Data Structure
When you add a mux.video field to your schema, Sanity stores it as a reference to a separate mux.videoAsset document. That's why you're seeing { _ref: '...' } - it's pointing to another document that contains all the Mux metadata.
The _ref value you mentioned matches the passthrough property because the Mux plugin uses passthrough to link Mux assets back to Sanity documents. This is completely normal behavior.
Using the Playback ID in Your Frontend
Once you have the playbackId, you can use it with Mux Player. For example, with @mux/mux-player-react:
import MuxPlayer from '@mux/mux-player-react'
export default function VideoPlayer({ playbackId }) {
if (!playbackId) return null
return <MuxPlayer playbackId={playbackId} />
}The dereferencing operator (->) is essential for working with any reference types in Sanity, whether it's Mux videos, regular file assets, or references between documents. For more details on querying references, check out the Sanity documentation on writing GROQ queries for references.
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.