-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Children required in contentBlocks #203
Comments
Hey @rafaelderolez yea these are a little tricky. @fritz-c posted a nice solution to this same issue with a codesandbox example here Applying that answer to what you have above, you'll basically want to make Here's a groqd arcade example with your data and what you might use as the query. Your query will basically end up looking something like this: export const homePageQuery = q('*')
.filter("_type == 'home' && language == $lang")
.grab({
history: q("history").grab({
story: q('story').filter().select({
'_type == "block"': ["{...}", q.contentBlock()],
'_type == "figure"': {
_type: q.literal("figure"),
asset: q('asset').grabOne('_ref', q.string())
// whatever other fields you want to
// grab on figure types
},
default: {
_key: q.string(),
_type: ['"unsupported"', q.literal("unsupported")],
unsupportedType: ["_type", q.string()],
},
}),
}),
})
.slice(0) |
@littlemilkstudio thanks for that! I missed your comment and am currently on holiday, will get back to you in 2 weeks. Feel free to close this Issue, your explanation and examples look like they should do the trick 👍🏼 |
Closing this for now, but please re-open if you're still having troubles getting this working! |
Hi @littlemilkstudio This is my content block query: q('body')
.filter()
.select({
'_type == "block"': ['{...}', q.contentBlock()],
'_type == "gallery"': [
`{..., "images": ${imagesListQuery('images').query}}`,
galleryQuery.schema,
],
'_type == "imageWithAlt"': nullToUndefined(imageWithAltQuery('').schema),
'_type == "imageWithAltAndCaption"': nullToUndefined(imageWithAltAndCaptionQuery().schema),
'_type == "quote"': ['{...}', quoteQuery],
'_type == "relatedPosts"': [
"{..., 'posts': posts[]->{title,'slug': slug.current, headline}}",
relatedPostsQuery,
],
'_type == "videoUrlWithCover"': videoUrlWithCoverQuery(''),
default: {
_key: q.string(),
_type: ['"unsupported"', q.literal('unsupported')],
unsupportedType: ['_type', q.string()],
},
}) The error appears after adding the |
Hey, I just started using groqd on a small side-project and have had a pretty good experience so far aside from this:
Error
Are custom types in
q.contentBlock(s)
not supported?Sanity
I have a object with a
block
in Sanity defined as suchGROQD
I query the content like this:
Data
And here's the actual data from the same groq query (done via Vision):
The text was updated successfully, but these errors were encountered: