Graphql SellingPlan query

GraphQL API can query Order.LineItems.SellingPlan.SellingPlanId

But is there a preferred way to get the actual Selling Plan from the SellingPlanId? It isn’t a connection, so can’t use the order query. There also seems to be no way to query SellingPlan by ID (neither in GraphQL or REST).

The only way to get the selling plan (that I can think of) is to query the product.sellingPlanGroups and repeatedly until you have all selling plan groups AND all selling plans for the product, then filter through these to find the plan with the matching ID. This makes some really nasty queries, so perhaps there is another way or Shopify could add a SellingPlan(id:ID) query? There is a SellingPlanGroup(id:ID) query; not sure why SellingPlan(id:ID) is missing?

Hi Appdev2023,

From looking into this, it does seem the only way to get the relevant selling plan is to get all the Selling Plans, and then search through them in your application to find the Selling Plan with the ID you’re interested in - which could be an inefficient process.

This could be improved if there was a SellingPlan(id: ID) query, as you suggested so I’ll connect with the product teams for this area and submit a feature request for this.

Hope this helps,

Hi again - After looking into this with some colleagues they suggested that with the ID you can use node to find a specific object like;

{
  node(id: "gid://shopify/SellingPlan/553123862") {
    id
    ... on SellingPlan {
      name
    }
  }
}

Can also use the plural nodes for multiple ids with an array;

{
  nodes(ids: ["gid://shopify/SellingPlan/553123862"]) {
    id
    ... on SellingPlan {
      name
    }
  }
}

node - https://shopify.dev/docs/api/admin-graphql/2023-07/queries/node
nodes - https://shopify.dev/docs/api/admin-graphql/2023-07/queries/nodes

Hope this helps!

1 Like

Thank you! I was just about to reply that the hunting through all groups and plans would likely exceed throttle anyway.

Query cost is 63253, which exceeds the single query max cost limit (1000)

I gave the node query a try and that works! Thank you