首页 > 解决方案 > 无法在类型“Query”graphql/template-strings 上查询字段“allDevArticles”以获取 dev.to 文章

问题描述

我正在使用 gatsby-source-dev gatsby 插件在我的 gatsby 页面上获取我的所有 dev.to 文章。 https://github.com/geocine/gatsby-source-dev

它工作正常,但最近它开始给我这个错误。

“无法在类型“查询”graphql/模板字符串上查询字段“allDevArticles””

并且无法在网站上获取我的最新文章。

我的 gatsby-config.js 看起来像这样


module.exports = {

  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `profile`,
        path: `./data`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-transformer-json`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-source-dev`,
      options: {
        username:'vish448'
      }
    },
  ],
}

我在页面上的 graphql 查询如下所示

export const query = graphql`
query ArticlePageQuery {
    allDevArticles {
    nodes {
      article {
        title
        url
        published_at(formatString: "DD MMM YYYY")
      }
    }
  }
}`

标签: graphqlgatsby

解决方案


我已经在 gatsby-config.js 中为 gatsby-source-dev 插件更新了配置,它工作正常。所以基本上这些字符串引号引起了问题。我已将这些引号更改为字符串文字 (``)


module.exports = {
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `profile`,
        path: `./data`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-transformer-json`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-source-dev`,
      options: {
        **username:`vish448`**
      }
    },
  ],
}


推荐阅读