🎤 Builder Talk: The Story Behind Lady Gaga’s Digital Experience – Register now

What Data Type Can I Use For a Boolean Value Or Null?

9 replies
Last updated: Sep 29, 2022
Just a super quick question, what data type can I use for a boolean value or null?
Sep 29, 2022, 7:26 PM
There is a boolean type! But dealing with the
null
part might be complicated. If the field has never been set, it just won't exist in the data. It won't be explicitly set to
null
.
Sep 29, 2022, 7:28 PM
ok - the data is coming in from next-auth - I actually dont need the field
Sep 29, 2022, 7:30 PM
I have another quick question, is it possible to extend a schema when using it? For instance I want to refer to product variant, but want to add additional fields such as quantity
Sep 29, 2022, 7:31 PM
or do I just build a new schema with these addtional fields?
Sep 29, 2022, 7:31 PM
You can wrap it in an object and add an additional field, but it may look different than you're expecting. This:
{
      name: 'compoundObject',
      type: 'object',
      fields: [
        {
          name: 'section',
          type: 'section',//section is another object with a string field
        },
        {
          name: 'addedField',
          type: 'string',
        },
      ],
    },
Gives this:
Sep 29, 2022, 7:35 PM
ooo ok great thanks!
Sep 29, 2022, 7:36 PM
hmmm I just tried to add the fields as you suggested:
    {
      title: "Cart Items",
      name: "cartItems",
      type: "array",
      of: [
        {
          title: "Product Variants Cart",
          type: "productVariant",
        },
        {
          name: "name",
          type: "string",
        },
        {
          name: "amount",
          type: "number",
        },
      ],
    },
Sep 29, 2022, 7:46 PM
but I’m still getting an error for those fields in sanity
Sep 29, 2022, 7:46 PM
It looks like you've put those in an array, which won't work quite the same way.
Sep 29, 2022, 7: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?

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
Deploying Next JS on VercelJan 20, 2021
Rendering nested block contentJan 18, 2021
DOMParser is not defined at defaultParseHtmlDec 3, 2020
List Arrays - Is it Possible to Fill a List Array Within a Schema Asynchronously?Mar 16, 2021
TypeError: Cannot Read Properties of Null (Reading 'jsonType')Sep 28, 2022
Error in custom validation rule for schema in Slack threadAug 18, 2023
Error in Next.js tutorial with event handlers in server components.Feb 28, 2024
How to populate a list of values in a Sanity schema using a separate fileSep 6, 2021
Discussion about the root layout for a website and how to properly implement it using Next.js.Apr 4, 2024
Hi all! Does anyone have problem on deoplloying on Vercel (Using Next. js as a frontend)? I have two test projects, andonce...Jan 25, 2021

Related contributions

Turbo Start Sanity
- Template

The battle-tested Sanity template that powers Roboto Studio's websites

Go to Turbo Start Sanity

Schema UI - Next.js Sanity Starter
- Template

A Next.js starter template with Next.js 15, Tailwind CSS, shadcn/ui, and Sanity CMS with Live Editing. Get production-ready React components with matching Sanity schemas and queries. Build dynamic pages faster while keeping full control over customization.

Serge Ovcharenko
Go to Schema UI - Next.js Sanity Starter

The Swaddle
- Made with Sanity

A new brand identity to represent a more mature company, to signify The Swaddle’s evolution from publisher to production house, combined with an easier to navigate platform that can surface multiple content types - drawing readers through The Swaddle’s content offering.

Nightjar
Go to The Swaddle