Is there an existing issue for this?
Code of Conduct
Code Sandbox link
No response
Bug report
conditionalByType ignores part of the result in a specific scenario.
When one type (e.g. 'heroSection') has its own parser, but another (e.g. 'block') does not, then the result for the latter is ignored during parsing.
This happens because conditionalParser returns an empty object in this case.
This does not work:
conditionalByType({
block: { // result is { _type: 'block' }
children: true,
style: true,
listItem: true,
markDefs: true,
level: true,
},
heroSection: (heroSection) => ({
title: true,
description: true,
photos: heroSection.field("photos[]").project((photo) => ({
src: photo.field("image").field("asset").deref().field("url"),
alt: true,
caption: true,
})),
columns,
})
})
But this does:
conditionalByType({
block: { // result is { _type: 'block', children: ..., style: ..., etc... }
children: true,
style: q.string(),
listItem: true,
markDefs: true,
level: true,
},
heroSection: (heroSection) => ({
title: true,
description: true,
photos: heroSection.field("photos[]").project((photo) => ({
src: photo.field("image").field("asset").deref().field("url"),
alt: true,
caption: true,
})),
columns,
})
})
Is there an existing issue for this?
Code of Conduct
Code Sandbox link
No response
Bug report
conditionalByTypeignores part of the result in a specific scenario.When one type (e.g. 'heroSection') has its own parser, but another (e.g. 'block') does not, then the result for the latter is ignored during parsing.
This happens because
conditionalParserreturns an empty object in this case.This does not work:
But this does: