๐Ÿ˜Ž Discover cool tips and tricks for customization in our next Developer Deep Dive virtual event - sign up now!

Is There a Way to Dereference (->) Only References?

3 replies
Last updated: Mar 2, 2021
if i have an array that includes both objects and references, is there any way to dereference (
->
) only the references, while leaving the other elements intact?
Mar 2, 2021, 4:54 PM
My
navigation
schema is an array of
references
to pages or url-based links (i.e. possibly external):

export default {
  name: "navigation",
  title: "Navigation",
  type: "object",
  fields: [
    {
      type: "array",
      name: "navigation",
      of: [
        {
          title: "Link to page",
          type: "reference",
          to: [{ type: "page" }],
        },
        { title: "External link", type: "navLink" },
        {
          title: "Dropdown menu",
          type: "navigation",
        },
      ],
    },
  ],
For this, we can ignore the nested array children, I just want to get the info on
page
references, while also having the
navLinks
not be sent to null when I deference all children (i.e.
navigation[] ->
.
I guess the overarching questions is how to use
select()
or other features to conditionally dereference/return projections
Mar 2, 2021, 4:57 PM
๐Ÿ˜ฎ i assumed that
_type == ___ =>
statements needed to be in a select! thanks
Mar 2, 2021, 4:59 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.

Was this answer helpful?