Issue with fetching Mux video type in Sanity schema using Groq
19 replies
Last updated: Feb 7, 2022
S
hi guys I have some issues working with the mux video type
Feb 7, 2022, 4:59 PM
S
if added it to my schema's like this
Feb 7, 2022, 4:59 PM
S
{ title: 'Content', name: 'content', type: 'array', of: [ { type: 'block' }, { type: "mux.video" }, { type: 'image', options: { hotspot: true }, fields: [ { name: 'caption', type: 'string', title: 'Caption', options: { isHighlighted: true // <-- make this field easily accessible } }, ] } ] },
Feb 7, 2022, 5:00 PM
S
but when I fetch it with groq like this
Feb 7, 2022, 5:00 PM
S
"lesson": *[slug.current == $lessonSlug][0] { _id, slug, title, content, }
Feb 7, 2022, 5:00 PM
S
its not actually fetching the mux video
Feb 7, 2022, 5:00 PM
S
it returns
Feb 7, 2022, 5:01 PM
S
1.
b.
*asset*:a.
*_ref*: "1eaec214-7eac-4b97-95fa-b843fa4373b2"
[[Prototype]]: Object2.
*_key*: "91498c943dd0"3.
*_type*: "mux.video"
Feb 7, 2022, 5:01 PM
S
like this
Feb 7, 2022, 5:01 PM
S
with no actual reference to the mux video ID I need
Feb 7, 2022, 5:01 PM
S
I know you are can fetch references with the arrow in groq but I don't know how to do it with the array type. for images it seems to do it on its own
Feb 7, 2022, 5:02 PM
D
content[]->{}
Feb 7, 2022, 5:11 PM
S
hmm
Feb 7, 2022, 5:14 PM
S
I got it working by using
content[] { ..., _type == "mux.video" => { asset->, }, }
Feb 7, 2022, 5:14 PM
D
yep, I am curious why you chose an array over document for the schema?
Feb 7, 2022, 5:17 PM
D
Glad you got it working.
Feb 7, 2022, 5:18 PM
S
its the content of a page
Feb 7, 2022, 8:02 PM
S
you would have made a document out of it and referenced it?
Feb 7, 2022, 8:02 PM
S
const lesson = { name: 'lesson', title: 'Lesson', type: 'document', fields: [ { title: 'Titel', name: 'title', type: 'string', }, { title: 'Slug', name: 'slug', type: 'slug', options: { source: 'title', maxLength: 200, // will be ignored if slugify is set slugify: input => input .toLowerCase() .replace(/\s+/g, '-') .slice(0, 200) } }, { title: 'Content', name: 'content', type: 'array', of: [ { type: 'block' }, { type: "mux.video" }, { type: 'image', options: { hotspot: true }, fields: [ { name: 'caption', type: 'string', title: 'Caption', options: { isHighlighted: true // <-- make this field easily accessible } }, ] } ] }, ] } export default lesson;
Feb 7, 2022, 8:02 PM
S
this is my entire schema
Feb 7, 2022, 8:02 PM
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.