首页 > 解决方案 > 更改 Graphql 查询,使其将每个产品显示在单独的行上

问题描述

Tl; Dr:我需要更改我的 Graphql 查询,以便它将每个产品显示在单独的行上,并在旁边的列中显示它的“rateProvider”(或运费)数据。


我正在使用 API Connector 插件在 Google 表格中使用以下查询检索 Shopify API 数据,并按照此处针对 GraphQL 的说明进行操作:https ://mixedanalytics.com/knowledge-base/access-shopify-data-in-google -床单/

该查询检索 Shopify 产品及其交付配置文件。但是所有产品都根据其交付配置文件显示在一行中?例如,如果有 10 个产品在交付配置文件中(100 美元运费),那么该交付配置文件的所有 10 个产品将与它们的交付配置文件数据一起显示在一行中,如下面的第一个示例。

但是我希望每个产品都显示在单独的行中,并在其旁边的列中显示交付配置文件数据,就像下面的第二个示例一样 *我也不确定如何为此查询设置正确的分页以提取“所有产品”。

示例 1:
产品 #1 | 产品#2 | deliveryProfile(100 美元运费)
产品 #1 | 产品#2 | 交付资料(50 美元运费)

示例:2:
产品 #1 | deliveryProfile(100 美元运费)
产品 #2 | deliveryProfile(100 美元运费)
产品 #1 | deliveryProfile(50 美元运费)
产品 #2 | 交付资料(50 美元运费)

query ($cursor: String) {
  deliveryProfiles (first: 5) {
    edges {
      node {
        profileItems (first: 5, after: $cursor) {
          edges {
           cursor
            node {
              product {
                id
                handle
              }
              variants (first: 5) {
                edges {
                  node {
                    id
                    title
                  }
                }
              }
            }
          }
        }
        profileLocationGroups {
          locationGroupZones(first: 5) {
            edges {
              node {
                methodDefinitions(first: 5) {
                  edges {
                    node {
                      rateProvider {
                        ... on DeliveryRateDefinition {
                          id
                          price {
                            amount
                          }
                        }
                        ... on DeliveryParticipant {
                          id
                          fixedFee {
                            amount
                            currencyCode
                          }
                          percentageOfRateFee
                          participantServices {
                            active
                            name
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }        
      }
    }
  }
}

标签: google-sheetsgraphqlshopify-api

解决方案


已解决:如果您使用 Google 表格的 API 连接器(附加组件)从 Shopify 导入数据并且您使用的是 GraphQL 查询,您必须进入 API 连接器的 [输出选项] 菜单并将报告样式更改为 [紧凑]在各自的行上显示各个记录。


推荐阅读