gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.29k stars 10.31k forks source link

Error: Cannot query field "frontmatter" on type "MarkdownRemark" - when no markdown is present #17087

Closed shehbazjafri closed 5 years ago

shehbazjafri commented 5 years ago

Description

Graphql gives an error when there are no markdown files present. The error goes away if there's at least one markdown file.

Steps to reproduce

Clear steps describing how to reproduce the issue. Please please please link to a demo project if possible, this makes your issue much easier to diagnose (seriously).

Expected result

Should not stop build if no markdown files are found.

Actual result

Build fails if no blog posts (markdown files) are found.

Environment

System: OS: Linux 4.4 Ubuntu 18.04.2 LTS (Bionic Beaver) CPU: (8) x64 Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz Shell: 5.4.2 - /usr/bin/zsh Binaries: Node: 12.6.0 - ~/.nvm/versions/node/v12.6.0/bin/node Yarn: 1.16.0 - /usr/bin/yarn npm: 6.10.3 - ~/.nvm/versions/node/v12.6.0/bin/npm Languages: Python: 2.7.15+ - /usr/bin/python npmPackages: gatsby: ^2.13.39 => 2.13.39 gatsby-image: ^2.2.8 => 2.2.8 gatsby-plugin-antd: ^2.0.2 => 2.0.2 gatsby-plugin-catch-links: ^2.1.2 => 2.1.2 gatsby-plugin-google-analytics: ^2.1.11 => 2.1.11 gatsby-plugin-manifest: ^2.2.4 => 2.2.4 gatsby-plugin-netlify-cms: ^4.1.6 => 4.1.6 gatsby-plugin-netlify-cms-paths: ^1.2.2 => 1.2.2 gatsby-plugin-offline: ^2.2.4 => 2.2.4 gatsby-plugin-react-helmet: ^3.1.2 => 3.1.2 gatsby-plugin-sass: ^2.1.3 => 2.1.3 gatsby-plugin-sharp: ^2.2.9 => 2.2.9 gatsby-plugin-sitemap: ^2.2.5 => 2.2.5 gatsby-plugin-styled-components: ^3.1.2 => 3.1.2 gatsby-remark-images: ^3.1.7 => 3.1.7 gatsby-source-filesystem: ^2.1.8 => 2.1.8 gatsby-transformer-remark: ^2.6.10 => 2.6.10 gatsby-transformer-sharp: ^2.2.4 => 2.2.4 npmGlobalPackages: gatsby-cli: 2.7.40

demeralde commented 5 years ago

@shehbazjafri hey did you figure out how to fix this?

shehbazjafri commented 5 years ago

@dspacejs Well, I wasn't able to find a proper solution, but apparently this is how Graphql works with Gatsby (or in general), so I used a workaround - I added a "hidden" property to the frontmatter and then added a dummy markdown file.

So, there would be one dummy file with hidden set to true, and every new file added (using a CMS) would have hidden set to false by default.

guitassinari commented 4 years ago

Shouldn't this issue be reopened? I'm having the same issue and there is no clear solution but a workaround.

dharmendrasha commented 4 months ago

same here