Error deploying GraphQL schema on Netlify due to removal of type, resolved by understanding schema changes.

12 replies
Last updated: Feb 7, 2022
I just committed a change to my studio & gatsby site to include a new content type, added via a plugin. Locally, everything works. On Netlify, Studio builds correctly, but my Gatsby site not. I get this error and I have no clue what to do now:
10:04:41 PM: > sanity graphql deploy --playground
10:04:42 PM: Dataset: production
10:04:42 PM: Tag: default
10:04:42 PM: - Checking for deployed API
10:04:42 PM: βœ” Checking for deployed API
10:04:42 PM: - Generating GraphQL schema
10:04:45 PM: βœ” Generating GraphQL schema
10:04:45 PM: - Validating GraphQL API
10:04:45 PM: ⚠ Validating GraphQL API
10:04:45 PM: Found BREAKING changes from previous schema:
10:04:45 PM:  - BlockOrMainImage was removed.
10:04:45 PM: Error: Dangerous changes found - falling back. Re-run the command with the `--force` flag to force deployment.
10:04:45 PM:     at confirmValidationResult (/opt/build/repo/studio/node_modules/@sanity/core/lib/actions/graphql/deployApiAction.js:273:11)
10:04:45 PM:     at deployApiActions (/opt/build/repo/studio/node_modules/@sanity/core/lib/actions/graphql/deployApiAction.js:157:15)
10:04:45 PM:     at processTicksAndRejections (node:internal/process/task_queues:96:5)
10:04:45 PM: 
10:04:45 PM: ────────────────────────────────────────────────────────────────
10:04:45 PM:   "build.command" failed                                        
10:04:45 PM: ────────────────────────────────────────────────────────────────
Should I run with
--force
? How can I investigate to understand more what is going on here?
Feb 3, 2022, 9:09 PM
Hello
user E
, I don’t think I removed a type at all. I have a single commit on
./studio/schemas/schema.js
, a file which was generated via this template . My change of yesterday was adding a plugin which contributes a content type via the parts system and which I added to `./studio/schemas/objects/bodyPortableText.js`:
    {
      type: "github.gist",
      options: { hotspot: true },
    },
So I’m quite firm I didn’t do anything with
BlockOrMainImage
. Also, I have no idea which queries are run at the moment as my Gatsby setup also came from the mentioned blog template project. What should I do now?
Feb 4, 2022, 11:47 AM
When I search in my project setup for
BlockOrMainImage
, I only found a partial match on line 176 in `web/.cache/schema.gql`:
union SanityBlockOrMainImage = SanityBlock | SanityMainImage
Feb 4, 2022, 12:00 PM
When I search in my project setup for
BlockOrMainImage
, I only found a partial match on line 176 in `web/.cache/schema.gql`:
union SanityBlockOrMainImage = SanityBlock | SanityMainImage
Feb 4, 2022, 12:00 PM
The
BlockOrMainImage
type is automatically generated when you deploy GraphQL. It seems that some underlying schema configuration changed, which means that combination of types no longer appears in your Sanity documents, so it's no longer being generated for you.
Is your site currently live and in use? It seems unlikely you're querying for this type, so it's probably safe for you to deploy using
--force
and then check out the site to make sure nothing's broken.
Feb 4, 2022, 12:33 PM
While the
MainImage
is still in my schema, I don’t have a document yet which contains an actual image. So this field probably is empty or nonexistent in all of my content. Could that be the underlying reason?
Feb 4, 2022, 12:36 PM
I'm not an expert on the GraphQL generation system, but I believe the
SanityBlockOrMainImage
type will have to exist if your schema allows this combination. Even if none of your content currently uses this combination, it could do in the future, so it's important for your GraphQL types to support this combination.
Could I take a look at your schema definition?
Feb 4, 2022, 12:39 PM
My blog is in a private repo at the moment. Can I have your GH userhandle, then I can provide you access?
Feb 4, 2022, 12:41 PM
Sure! It's
juice49
.
Feb 4, 2022, 12:43 PM
FYI, the plugin with content type I added is this self-made plugin: https://github.com/ringods/sanity-plugin-github
Feb 4, 2022, 12:47 PM
user E
I think I found it, and finally understand a lot better how more of the graphql generation works. Given I added a third content type option for my blog post body, the generated graphql union type changed from:
union BlockOrMainImage = Block | MainImage
to

union BlockOrGithubGistOrMainImage = Block | GithubGist | MainImage
Indeed,
BlockOrMainImage
was removed, but not because I removed one of the existing content options, but because I added one. Wow, what an adventure was this. πŸ™‚
Feb 6, 2022, 5:20 PM
user E
I think I found it, and finally understand a lot better how more of the graphql generation works. Given I added a third content type option for my blog post body, the generated graphql union type changed from:
union BlockOrMainImage = Block | MainImage
to

union BlockOrGithubGistOrMainImage = Block | GithubGist | MainImage
Indeed,
BlockOrMainImage
was removed, but not because I removed one of the existing content options, but because I added one. Wow, what an adventure was this. πŸ™‚
Feb 6, 2022, 5:20 PM
Aha! That makes sense. Nice debugging πŸ™‚.
The warning is a little difficult to understand at first... and scary if you're not sure why something has been removed.
Feb 7, 2022, 9:27 AM

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?