How to avoid breaking changes when redeploying Sanity API

5 replies
Last updated: Feb 8, 2021
Hello again! I went to re-deploy my api and got a lot of warnings re: dangerous changes. Should I be concerned about these? Is there a specific reason these would all be changing like this? I don’t remember modifying the schemas this much. Here’s a sample:
Found BREAKING changes from previous schema:
- BlogPost._id changed type from ID! to ID.
- BlogPost._type changed type from String! to String.
- BlogPost._createdAt changed type from DateTime! to DateTime.
- BlogPost._updatedAt changed type from DateTime! to DateTime.
- BlogPost._rev changed type from String! to String.
- Document._id changed type from ID! to ID.
- Document._type changed type from String! to String.
- Document._createdAt changed type from DateTime! to DateTime.
- Document._updatedAt changed type from DateTime! to DateTime.
- Document._rev changed type from String! to String.
- SanityImageAsset._id changed type from ID! to ID.
- SanityImageAsset._type changed type from String! to String.
- SanityImageAsset._createdAt changed type from DateTime! to DateTime.
- SanityImageAsset._updatedAt changed type from DateTime! to DateTime.
[….]
AI Update

Good news - in the vast majority of cases, these warnings about breaking changes are not something you need to worry about!

What's Happening

These changes you're seeing (like BlogPost._id changed type from ID! to ID) are related to a schema correction Sanity made a while back. The GraphQL schema previously indicated that certain system fields (_id, _type, _createdAt, _updatedAt, _rev) were always present (marked with ! in GraphQL, meaning non-nullable). However, Sanity discovered this wasn't technically accurate - when document types are embedded inside other documents, these fields might not always be present.

The change from ID! to ID (and String! to String, DateTime! to DateTime) simply means these fields are now correctly marked as nullable in the GraphQL schema. This is a more accurate representation of how Sanity actually works.

Should You Be Concerned?

For most use cases, no. This is a correction to make the schema more accurate, not a change to your actual content or how Sanity functions. Your content hasn't changed, and the fields will still be present in your documents where they should be.

How to Handle This

You have two options:

  1. Accept the change (recommended): Simply proceed with the deployment. The warnings are informing you of the schema change, but it's unlikely to cause issues with your existing queries.

  2. Use the flag to keep old behavior: If you want to maintain the old non-nullable behavior, you can use the --non-null-document-fields flag:

sanity graphql deploy --non-null-document-fields

This will deploy your GraphQL API with the system fields marked as non-nullable, just like before.

Why You're Seeing This Now

You mentioned not remembering modifying schemas this much - that's because you didn't! This change is on Sanity's side to correct how the GraphQL schema represents these system fields. It's appearing now because you're redeploying your GraphQL API, which triggers the schema comparison between your current deployment and the previous one.

Remember, the GraphQL API needs to be redeployed whenever you update your schema - it doesn't automatically update when you deploy your Studio. This is a normal part of the workflow, and these particular warnings are just Sanity being transparent about the schema corrections they've made.

Show original thread
5 replies
Hi Stu!
In the vast majority of cases this particular change is not something you should be worried about.

A while back we discovered that the schema incorrectly said that these fields were "always" present - but that people were embedding document types inside of other documents, which makes that assumption false (in those cases).
We added a flag to let you get the old behavior back, should you not want the change - add the
--non-null-document-fields
flag to the command. Eg:

sanity graphql deploy --non-null-document-fields
Ok, good to know - thanks a lot!
We added a flag to let you get the old behavior back, should you not want the change - add the
--non-null-document-fields
flag to the command. Eg:

sanity graphql deploy --non-null-document-fields
Hi Stu!
In the vast majority of cases this particular change is not something you should be worried about.

A while back we discovered that the schema incorrectly said that these fields were "always" present - but that people were embedding document types inside of other documents, which makes that assumption false (in those cases).

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?