我们如何使用 gatsby-source-shopify 插件从 Gatsby 中的 Shopify Headless 获取博客文章和页面?

问题描述 投票:0回答:1

我计划将我的网站从 Shopify 迁移到 Shopify Headless + Gatsby,但我遇到了插件 gatsby-source-shopify 的问题。它可以为产品和产品相关数据创建节点,但不能为博客文章创建节点。有什么方法可以获取博客文章还是我必须在 Gatsby 中手动创建它们。

这是我的 gatsby-source-shopify 插件的配置。

      resolve: `gatsby-source-shopify`,
      options: {
        password: process.env.GATSBY_SHOPIFY_PASSWORD,
        storeUrl: process.env.GATSBY_SHOPIFY_STORE_URL,
        shopifyConnections: ["collections"],
      },
    },

它提供了 GraphQL 中的产品和产品相关节点。 Available Nodes in GraphQL Screenshot

我尝试谷歌搜索,但所有教程和 gatsby-source-shopify 文档都专注于检索产品数据。

谢谢你们。

graphql gatsby shopify-api
1个回答
0
投票

您首先必须确保您的 env 文件具有所有正确的凭据,才能正确连接到您在 shopify 中创建的自定义应用程序。

我的环境文件:

enter image description here

现在根据 gatsby 文档,我们必须创建一个新的源,我们将其称为“storefront”。您的 Gatsby-config.js 文件应如下所示。

enter image description here

运行“Gatsby clean”,然后在终端中为您的 gatsby 运行 gatsbydevelop 命令。如果一切顺利的话。您应该能够打开 http://localhost:8000/___graphql 或您正在运行的任何端口(您可以在终端中找到该信息)

enter image description here

打开http://localhost:8000/___graphql,您应该能够在资源管理器中看到店面。

enter image description here

创建一个查询并获取它,我已经完成了一个适合我的查询

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.