【问题标题】:Cannot query field "allDevArticles" on type "Query" graphql/template-strings for fetching dev.to articles无法在类型“Query”graphql/template-strings 上查询字段“allDevArticles”以获取 dev.to 文章
【发布时间】:2020-10-27 14:28:41
【问题描述】:

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

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

“无法在类型“Query”graphql/template-strings 上查询字段“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")
      }
    }
  }
}`

【问题讨论】:

  • 您确定用户名已按照您的描述进行配置?如果用户名错误,您将收到您描述的错误消息。一般来说,错误意味着“没有找到文章”。见github.com/gatsbyjs/gatsby/issues/3344
  • 谢谢@ehrencrona,你是对的。

标签: graphql gatsby


【解决方案1】:

我已经在 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`**
      }
    },
  ],
}

【讨论】:

    猜你喜欢
    • 2021-11-13
    • 2020-06-27
    • 2020-10-29
    • 2016-12-05
    • 2019-10-09
    • 2021-04-10
    • 1970-01-01
    • 2021-09-02
    • 2020-02-28
    相关资源
    最近更新 更多