在 Shopify SellingPlanPricingPolicy 的联盟上执行 GraphQL 选择

vis*_*nki 3 shopify graphql

我正在尝试使用 Shopify 的 Graphql API 获取联合数据,但无法找到有关在联合中选择数据的任何文档。

这是我当前的查询:

query subscriptionPlans {
  sellingPlanGroup(id: 1234) {
    id
    name
    sellingPlans(first: 1) {
      edges {
        node {
          id
          billingPolicy {
            ... on SellingPlanRecurringBillingPolicy {
              interval
              intervalCount
            }
          }
          pricingPolicies {
            on
            SellingPlanRecurringPricingPolicy {
              afterCycle
              adjustmentType
              adjustmentValue {
                on
                SellingPlanPricingPolicyPercentageValue {
                  percentage
                }
                on
                MoneyV2 {
                  amount
                  currencyCode
                }
              }
            }
          }
        }
      }
    }
  }
}

Run Code Online (Sandbox Code Playgroud)

在这种情况下我能够检索 sellPlans。当我到达 SellingPlanPricingPolicy 部分时,我遇到了问题。我收到错误:

Selections can't be made directly on unions (see selections on SellingPlanPricingPolicy)
Run Code Online (Sandbox Code Playgroud)

但是,我无法找到任何有关使用以下文档进行选择的文档: https: //shopify.dev/docs/admin-api/graphql/reference/products-and-collections/ sellplanpricingpoli ...。

任何对此的帮助将不胜感激。我只需要一个如何选择此信息的示例。

and*_*dig 5

在https://graphql.org/learn/queries/#meta-fields中找到了答案。对于sponsorEntity,它看起来像这样:

      sponsorEntity {
        ... on User {
          name
        }
      }
Run Code Online (Sandbox Code Playgroud)

解决方案是选择联合的相应子类型的属性。