gatsby: Cannot query field "allMarkdownRemark" on type "Query".

Description

Error Processing Netlify CMS Output with Gatsby

gatsby-node.js

const path = require(`path`)

exports.createPages = async ({ actions, graphql, reporter }) => {
  const { createPage } = actions

  const blogPostTemplate = path.resolve(`src/templates/blogTemplate.js`)

  const result = await graphql(`
    {
      allMarkdownRemark(
        sort: { order: DESC, fields: [frontmatter___date] }
        limit: 1000
      ) {
        edges {
          node {
            frontmatter {
              path
            }
          }
        }
      }
    }
  `)

  // Handle errors
  if (result.errors) {
    reporter.panicOnBuild(`Error while running GraphQL query.`)
    return
  }

  result.data.allMarkdownRemark.edges.forEach(({ node }) => {
    createPage({
      path: node.frontmatter.path,
      component: blogPostTemplate,
      context: {}, // additional data can be passed via context
    })
  })
}
Image 2019-09-22 at 11 23 27 pm

in gatsby-config.js:

plugins: [
    `gatsby-plugin-sitemap`,
    `gatsby-plugin-netlify-cms`,
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/static/images`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `blog`,
        path: `${__dirname}/blog`,
      },
    },
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#FF54AC`,
        display: `minimal-ui`,
        icon: `${__dirname}/static/images/icons/favicon-196x196.png`, // This path is relative to the root of the site.
      },
    },
    `gatsby-plugin-sass`,
    {
      resolve: "gatsby-plugin-web-font-loader",
      options: {
        google: {
          families: ["PT Serif", "Poppins"],
        },
        custom: {
          families: ["Inter", "Poppins", "Avenir", "Brandon Grotesque"],
          urls: ["/fonts/fonts.css"],
        },
      },
    },
  ],

Everything else is as per the tutorial steps

Steps to reproduce

Follow the steps to add netlifyCMS to an existing project: https://www.gatsbyjs.org/docs/sourcing-from-netlify-cms/ and https://www.gatsbyjs.org/docs/adding-markdown-pages/

Result

 ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "allMarkdownRemark" on type "Query".

File: gatsby-node.js:8:24

 ERROR 

Error while running GraphQL query.

success createPages - 0.072 s
success createPagesStatefully - 0.115 s
success onPreExtractQueries - 0.015 s
success update schema - 0.040 s

 ERROR #85907  GRAPHQL

There was an error in your GraphQL query:

- Unknown field 'markdownRemark' on type 'Query'.

File: src/templates/blogTemplate.js

Environment

System:
    OS: macOS 10.14.1
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.15.3 - /usr/local/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.11.3 - /usr/local/bin/npm
  Languages:
    Python: 2.7.10 - /usr/bin/python
  Browsers:
    Chrome: 76.0.3809.132
    Safari: 12.0.1
  npmPackages:
    gatsby: ^2.7.5 => 2.15.20
    gatsby-cli: ^2.6.5 => 2.7.49
    gatsby-image: ^2.2.19 => 2.2.19
    gatsby-plugin-manifest: ^2.2.18 => 2.2.18
    gatsby-plugin-netlify-cms: ^4.1.17 => 4.1.17
    gatsby-plugin-offline: ^2.1.1 => 2.1.1
    gatsby-plugin-react-helmet: ^3.0.12 => 3.0.12
    gatsby-plugin-sass: ^2.0.11 => 2.0.11
    gatsby-plugin-sitemap: ^2.2.13 => 2.2.13
    gatsby-plugin-web-font-loader: ^1.0.4 => 1.0.4
    gatsby-source-filesystem: ^2.1.26 => 2.1.26
    gatsby-transformer-remark: ^2.6.24 => 2.6.24
  npmGlobalPackages:
    gatsby-cli: 2.7.49

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (2 by maintainers)

Most upvoted comments

@mryechkin going about what you have posted, probably the issue could be the location of the markdown, more specifically where gatsby-source-filesystem is looking for the content. As technically the pages folder in Gatsby is considered a special folder. As a test can you try to move the content to where the documentation points out. Adjust gatsby-config.js. Clear the cache with gatsby clean and issue a new build with gatsby develop and see if the issue persists? If so, report back and we could take it from there.

Yep, I hit a related problem here : https://www.gatsbyjs.org/tutorial/part-four/#your-first-graphql-query

Cannot query field “frontmatter” on type “MarkdownRemark”. 52:11 error Cannot query field “frontmatter” on type “MarkdownRemark” graphql/template-strings

Seems like I need an explicit call to gatsby-transformer-remark in my gatsby-config.js And need to npm install --save gatsby-transformer-remark

@videohead you were correct - I was working on a project that didn’t have gatsby-transformer-remark in the gatsby-config.js. Simply adding:

{ resolve: `gatsby-transformer-remark` }

to gatsby-config.js fixed it. (Doing npm install --save gatsby-transformer-remark is of course still required 😄 ) Hard one to debug!