Performing a gql selection on a union

Nathan_Pope1
Shopify Partner
2 0 2

I am trying to get union data using the graphql api and am unable to find any documentation on selecting data in unions.

Here is my current query:

 

{
    sellingPlanGroups (first: 5) {
        edges {
            cursor
            node {
                id
                name
                sellingPlans(first: 25) {
                    edges {
                        node {
                            id
                            ... on SellingPlanPricingPolicy {
                                __typeName
                                adjustmentType
                                adjustmentValue
                            }
                        }
                    }
                }
            }
        }
    }
}

 

 

I am able to retrieve the sellingPlans in this scenario. When I get to the SellingPlanPricingPolicy portion I run into issues. I am receiving the error:

Selections can't be made directly on unions (see selections on SellingPlanPricingPolicy) 

 However, I am unable to find any documentation on making selections using the documentation at: https://shopify.dev/docs/admin-api/graphql/reference/products-and-collections/sellingplanpricingpoli...

Any help with this would be appreciated. I just need an example of how to select this information.

BStubbs
Shopify Partner
127 14 51

I'm having exactly the same problem. The docs seem a bit limited here.

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
0 Likes
darcybrown
New Member
2 0 4

For anyone who stumbles on this, I got this to work using:

query subscriptionPlans {
  sellingPlanGroups(first: 10) {
    edges {
      node {
        id
        name
        options
        merchantCode
        description
        sellingPlans(first: 10) {
          edges {
            node {
              id
              name
              options
              billingPolicy {
                ... on SellingPlanRecurringBillingPolicy {
                  interval
                  intervalCount
                }
              }
              deliveryPolicy {
                ... on SellingPlanRecurringDeliveryPolicy {
                  interval
                  intervalCount
                }
              }
              pricingPolicies {
                ... on SellingPlanFixedPricingPolicy {
                  adjustmentType
                  adjustmentValue {
                    ... on SellingPlanPricingPolicyPercentageValue {
                      percentage
                    }
                    ... on MoneyV2 {
                      amount
                      currencyCode
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

 

Webdibs
Tourist
5 0 3

I could do it by testing on Shopify GraphiQL App first, then tweaking until worked. Here's the query I'm using:

 

pricingPolicies {
  ... on SellingPlanFixedPricingPolicy {
      adjustmentType
      adjustmentValue {
        ... on SellingPlanPricingPolicyPercentageValue {
          percentage
        }
        ... on MoneyV2 {
          amount
          currencyCode
        }
      }
    }
  ... on SellingPlanRecurringPricingPolicy  {
      afterCycle
      adjustmentType
      adjustmentValue {
        ... on SellingPlanPricingPolicyPercentageValue {
          percentage
        }
        ... on MoneyV2 {
          amount
          currencyCode
        }
      }
  }
}