I am using Gatsby with Netlify CMS. I use gatsby-transformer-sharp for various image manipulations.
In Netlify CMS, if a user deletes an image, the frontmatter value becomes an empty string, e.g:
my-blog-post.md:
---
image: ''
---
This causes gatsby-transformer-sharp to error, when I am querying Graphql:
Error Field "image" must not have a selection since type "String" has no subfields.
This seems to be because Gatsby/Graphql has inferred the image field to be a string.
So I created a schema.md
file, so there will always be at least one entry with a valid image in place:
_schema.md:
---
image: /some-dummy-image.jpg
---
Which seems to partially fix the problem - the build only fails occasionally. But it does still fail. I think it must infer its schema from the first markdown file it comes across - sometimes it finds _schema.md
first, sometimes it finds my-blog-post.md
first.
Has anyone managed to find a solution to this?
_schema.md
). The problem is that this sometimes fails. Sometimes Gatsby will incorrectly infer theimage
field to be a string (becausemy-blog-post.md
containsimage: ''
). I'm not sure how Gatsby decides which file to use when it infers the schema. I put an underscore in my dummy post filename so it would come first alphabetically when read from the file system, but still it doesn't always work. – Rich