【问题标题】:cannot query field "allMdx" on type "Query"无法在“查询”类型上查询字段“allMdx”
【发布时间】:2021-09-02 00:29:00
【问题描述】:

我是 GraphiQl 的新手,我正在从 here 流式教学

而且我是 Gatsby 的新手,毕竟需要安装插件(来自 gatsby 官方文档的指南),当我想继续此链接时:http://localhost:8000/___graphql 然后如果我将鼠标悬停在 allMdx 上,则显示错误.

像这样:

但是官方文档一切正常,我不知道我的问题在哪里。

任何更新问题!

我用过gatsby v3

我的初始查询也与this不匹配

请给点建议。

【问题讨论】:

    标签: reactjs graphql gatsby


    【解决方案1】:

    基本上,GraphQL 游乐场 (localhost:8000/___graphql) 告诉您您没有创建 allMdx 节点。所有可用节点的列表位于左列(allFile、allDirectory 等)。

    您需要设置文件系统以允许 Gatsby 通过以下方式推断该节点:

    npm install gatsby-source-filesystem
    

    那么,在你的gatsby-config.js:

    module.exports = {
      siteMetadata: {
        title: "My First Gatsby Site",
      },
      plugins: [
        "gatsby-plugin-gatsby-cloud",
        "gatsby-plugin-image",
        "gatsby-plugin-sharp",
        {
          resolve: "gatsby-source-filesystem",
          options: {
            name: `blog`,
            path: `${__dirname}/blog`, // <-- the folder where you have the .mdx files
          }
        },
      ],
    };
    

    如果您在/blog 文件夹中有一些 MDX 文件,Gatsby 将生成正确的节点 (allMdx),以便您查询它们。

    通过gatsby clean &amp;&amp; gatsby develop重新启动并清理您的服务器。

    接下来的步骤是通过添加一些配置来查询数据,例如:

    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        defaultLayouts: {
          posts: require.resolve("./src/components/blog-layout.js"),
          default: require.resolve("./src/components/layout.js"),
        },
      },
    },
    

    注意:您需要先安装gatsby-plugin-mdx 插件

    您可以查看以下教程:https://www.digitalocean.com/community/tutorials/gatsbyjs-mdx-in-gatsby

    【讨论】:

    • 谢谢我忘记重启服务器了..:D
    猜你喜欢
    • 1970-01-01
    • 2021-06-03
    • 2021-10-09
    • 2021-07-26
    • 2021-02-03
    • 2020-07-27
    • 2018-08-30
    • 2018-04-21
    • 2020-05-31
    相关资源
    最近更新 更多