首页 > 解决方案 > Gatsby:GraphQL 无法查询类型 \"Query\" 上的字段 \"allMarkdownRemark\"

问题描述

我是 Gatsby 的新手,正在尝试构建博客功能。我已经安装了gatsby-source-filesystemgatsby-transformer-remarkgatsby-plugin-catch-links。我在pages目录中有博客文章,每个博客文章都在pages. 当我尝试查询博客文章时,pages我会出现以下错误:

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

这是我的项目的结构:

在此处输入图像描述

这是我的配置文件:

module.exports = {
  siteMetadata: {
    title: `Gatsby Crash Course`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-catch-links`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `pages`,
        path: `${__dirname}/src/pages/`
      },
    },
    `gatsby-transformer-remark`,
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.dev/offline
    // `gatsby-plugin-offline`,
  ],
}

我的 GraphQL 查询:

{
  allMarkdownRemark {
    edges {
      node {
        frontmatter {
          path
          title
          date 
          author
        }
      }
    }
  }
}

如何修复此错误并allMarkdownRemark正常工作并从中检索博客文章pages

标签: reactjsgraphqlfilesystemsgatsbygatsby-plugin

解决方案


推荐阅读