&引用;盖茨比源图“ql”;不';t链接到Drupal8

&引用;盖茨比源图“ql”;不';t链接到Drupal8,drupal,graphql,drupal-8,gatsby,Drupal,Graphql,Drupal 8,Gatsby,这是我的gatsby-config.js文件 当我运行盖茨比清洁和盖茨比发展或只是盖茨比建设我得到 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 configura

这是我的gatsby-config.js文件 当我运行盖茨比清洁和盖茨比发展或只是盖茨比建设我得到

  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",
      },
    },
  ],
}
成功创建SchemaCustomization-0.005s
错误#11321插件
“gatsby source graphql”在运行sourceNodes生命周期时引发错误:
JSON中位置0处出现意外标记<
ServerParseError:JSON中位置0处出现意外标记<
-JSON.parse
-index.js:35
[测试盖茨比]/[阿波罗链接http公共]/lib/index.js:35:25
-下一个_tick.js:68进程。_tick回调
内部/流程/下一步勾选js:68:7
未完成源节点和变换节点-0.506s
我的Drupal8站点是安装了graphql模块的新站点。盖茨比的网站也是全新的

在工作了一段时间后,我在周一开始关注这个问题。我的盖茨比没有代码更改,但突然间我无法再获取drupal数据


似乎很少有使用“gatsby source graphql”插件的例子,所以如果有人能帮忙,请在我的例子中,这是Drupal中的权限问题。我去管理员那里解决了这个问题→ 人→ 权限,并为匿名用户设置与GraphQL相关的所有权限。

使用令牌的Drupal Graph QL模块。您可以使用或。我使用了简单的Oauth,并通过以下步骤解决了我的问题:

  • 使用composer安装Simple Oauth模块,使其安装依赖项
    $composer require drupal/Simple\u Oauth
    ,然后启用该模块

  • 为第三方应用创建用户角色,并为该角色分配内容查看权限

  • admin/config/people/simple_oauth
    中添加令牌过期时间,使用提供的按钮生成密钥(确保它们在drupal web根目录之外生成),并将路径添加到公钥和私钥文件

  • admin/config/services/consumer
    中添加新使用者(或使用默认使用者)

  • secret
    字段中添加一个秘密密码,并选择在
    作用域下创建的新角色,然后保存配置页面

  • 向您的站点发出post请求
    https://intl-pgs-rsm-growth-platform.pantheonsite.io/oauth/token
    使用curl或postman使用以下正文字段生成令牌:

  • 如果成功,post请求应返回访问令牌。将您的令牌添加到应用程序的
    .env.development
    文件中,并使用授权标题更新您的
    gatsby config.js
    文件:(可以找到有关在gatsby应用程序中设置环境变量的更多信息)
  • 简单Oauth设置步骤的视频教程可以

    有关此设置过程的更多信息,请参阅

    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
    
    grant_type: password
    client_id: The client id generated `admin/config/services/consumer`
    client_secret: The secret you entered in step 4
    username: A user in your drupal site that has the role you created
    password: The password assigned to that account
    
    {
        resolve: "gatsby-source-graphql",
        options: {
            typeName: "DRUPAL",
            fieldName: "drupal",
            url: "https://intl-pgs-rsm-growth-platform.pantheonsite.io/graphql",
            headers: {
                "Authorization": `Bearer ${process.env.GATSBY_API_TOKEN}`
            },
        },
    },