Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Is it possible to set a weak reference through a mutation in Sanity.io?

2 replies
Last updated: Feb 2, 2024
Is it possible to set a weak reference through a mutation? My current mutation is this:

mutation = {
            mutations: [
                {
                    create: {
                        _id: crypto.randomUUID(),
                        _type: "team",
                        title: team.name,
                        badgeUrl: team.logo,
                        footballApiId: team.id,
                        isNationalTeam: team.national,
                        country: {
                            _type: 'reference',
                            weak: true,
                            _ref: sanityCountry._id
                        },
                        slug: {
                            type: '_slug',
                            current: slugify(`${team.id}-${team.name}`)
                        }
                    }
                }
            ]
Yet, when I add the
weak: true
to the country reference, it returns this error code when this prop is included:
ERROR TypeError: Cannot read properties of undefined (reading '0')

So my question is, is this possible?
Jan 24, 2024, 9:37 AM
I think you need to use
_weak
instead.
Jan 24, 2024, 9:35 PM
This resolved it, thank you!
Feb 2, 2024, 12:52 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?