使用 MDX 在 Gatsby 博客中添加 featuresImage

mdu*_*bus 7 graphql gatsby

我正在尝试在我的 Gatsby 博客上添加特色图片,但无法使其正常工作。我在这里和那里尝试了几件事情,但我一直收到此错误消息:Field "featuredImage" must not have a selection since type "String" has no subfields.

这是我的博客结构:

src
 |- images
   |- house.jpeg
 | - pages
   |- actualites
     |- house.mdx
Run Code Online (Sandbox Code Playgroud)

house.mdx有以下frontmatter:

---
title: House
path: /house
date: 2019-01-29
featuredImage: ../../images/house.jpeg
---
Run Code Online (Sandbox Code Playgroud)

gatsby-plugin看起来像这样:

plugins: [
    `gatsby-plugin-resolve-src`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/src/images`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/src/pages`,
      },
    },
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          {
            resolve: `gatsby-remark-images`,
            options: {
              maxWidth: 800,
            },
          },
        ],
      },
    },
    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        gatsbyRemarkPlugins: [
          {
            resolve: `gatsby-remark-images`,
            options: {
              maxWidth: 1200,
            },
          },
        ],
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
  ],
Run Code Online (Sandbox Code Playgroud)

我不知道我做错了什么...... http://localhost:8000/___graphql 向我展示了我的featuredImage但不是图像的子字段,所以我想它不明白我的字段是一个图像.

你能帮我指出我所缺少的吗?

谢谢

mdu*_*bus 1

我终于能够让它发挥作用了。

问题是我是在请求allSitePage而不是allMdx在我的 graphQL 中请求。现在我可以将我的路径视为图像并请求其所有子字段。