首页 > 解决方案 > “gatsby-source-graphql”没有链接到 Drupal 8

问题描述

  siteMetadata: {
    title: `Gatsby Default Starter`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    {
      resolve: "gatsby-source-graphql",
      options: {
        // Arbitrary name for the remote schema Query type
        typeName: "DRUPAL",
        // Field under which the remote schema will be accessible. You'll use this in your Gatsby query
        fieldName: "drupal",
        // Url to query from
        url: "https://intl-pgs-rsm-growth-platform.pantheonsite.io/graphql",
      },
    },
  ],
}

这是我的 gatsby-config.js 文件当我运行 gatsby clean && gatsby develop 或只是 gatsby build 我得到

success createSchemaCustomization - 0.005s

 ERROR #11321  PLUGIN

"gatsby-source-graphql" threw an error while running the sourceNodes lifecycle:

Unexpected token < in JSON at position 0



  ServerParseError: Unexpected token < in JSON at position 0

  - JSON.parse

  - index.js:35 
    [test-gatsby]/[apollo-link-http-common]/lib/index.js:35:25

  - next_tick.js:68 process._tickCallback
    internal/process/next_tick.js:68:7


not finished source and transform nodes - 0.506s

我的 Drupal 8 站点是安装了 graphql 模块的新站点。盖茨比网站也是全新的。

在工作了一段时间后,我周一开始遇到这个问题。我的 gatsby 没有代码更改,但突然之间我不再能够获取 drupal 数据。

使用“gatsby-source-graphql”插件的例子似乎很少,所以如果有人可以帮忙,请做

标签: drupalgraphqldrupal-8gatsby

解决方案


就我而言,这是 Drupal 中的权限问题。我通过转到管理员 → 人员 → 权限并为匿名用户设置与 GraphQL 相关的所有权限来解决它。


推荐阅读