盖茨比:gatsby-source-graphql:无法读取未定义的属性“ createPageDependency”

时间:2019-12-12 06:49:21

标签: gatsby

我正在为fireblog(https://fireblogcms.com/)构建一个Gatsby入门主题,该主题具有GraphQL API。所以我尝试了gatsby-source-graphql插件,这似乎是可行的方法:

按照以下页面上的说明进行操作:https://www.gatsbyjs.org/packages/gatsby-source-graphql/然后访问http://localhost:8000/___graphql时,在我的新类型上运行GraphQL查询时遇到了Cannot read property 'createPageDependency' of undefined这个问题。

要复制:

  • yarn add gatsby-source-graphql
  • 将此配置添加到gatsby-config.js
  plugins: [
    // Simple config, passing URL
    {
      resolve: "gatsby-source-graphql",
      options: {
        // This type will contain remote schema Query type
        typeName: "fireblog",
        // This is field under which it's accessible
        fieldName: "fireblog",
        // Url to query from
        url: "https://api.fireblogcms.com/graphql/blog/5de7a2934360f60004130881"
      }
    },
  //...
  ], 

转到http://localhost:8000/___graphql

并运行查询:

{
  fireblog {
    posts(last: 20) {
      edges {
        node {
          title
        }
      }
    }
  }
}

预期结果

我希望查询能够正常运行,或者出现一条错误消息,向我解释下一步如何使该查询正常工作。

实际结果

发生了什么事:

{
  "errors": [
    {
      "message": "Cannot read property 'createPageDependency' of undefined",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "fireblog"
      ]
    }
  ],
  "data": null
}

gatsby info --clipboard

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4960HQ CPU @ 2.60GHz
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.12.0 - ~/.nvm/versions/node/v10.12.0/bin/node
    Yarn: 1.17.3 - ~/.yarn/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.12.0/bin/npm
  Languages:
    Python: 2.7.10 - /usr/bin/python
  Browsers:
    Chrome: 78.0.3904.108
    Firefox: 69.0.3
    Safari: 13.0.3
  npmPackages:
    gatsby: ^2.1.10 => 2.1.10
    gatsby-image: ^2.0.29 => 2.0.29
    gatsby-plugin-feed: ^2.0.13 => 2.0.13
    gatsby-plugin-google-analytics: ^2.0.14 => 2.0.14
    gatsby-plugin-html2amp: ^0.4.0 => 0.4.0
    gatsby-plugin-manifest: ^2.0.18 => 2.0.18
    gatsby-plugin-offline: ^2.0.24 => 2.0.24
    gatsby-plugin-react-helmet: ^3.0.6 => 3.0.6
    gatsby-plugin-sharp: ^2.0.21 => 2.0.21
    gatsby-plugin-typography: ^2.2.7 => 2.2.7
    gatsby-remark-copy-linked-files: ^2.0.9 => 2.0.9
    gatsby-remark-images: ^2.0.6 => 2.0.6
    gatsby-remark-prismjs: ^3.2.4 => 3.2.4
    gatsby-remark-responsive-iframe: ^2.0.9 => 2.0.9
    gatsby-remark-smartypants: ^2.0.8 => 2.0.8
    gatsby-source-filesystem: ^2.0.20 => 2.0.20
    gatsby-source-graphql: ^2.1.28 => 2.1.28
    gatsby-transformer-remark: ^2.2.5 => 2.2.5
    gatsby-transformer-sharp: ^2.1.14 => 2.1.14
  npmGlobalPackages:
    gatsby-cli: 2.8.8

1 个答案:

答案 0 :(得分:0)

问题似乎出在我的节点版本上,我对节点12.4.0的最后一次测试没问题。如果我没记错的话,我以前是在节点10.13.0上