Skip to content

conditionalByType ignores part of the result when validation is missing #400

@ntvangoor

Description

@ntvangoor

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's 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,
  })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions