Out now! Check out the Poll results: Do you have a Shopify store?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Graphql SellingPlan query

Solved

Graphql SellingPlan query

appdev2023
Shopify Partner
21 2 3

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?

Accepted Solution (1)

Liam
Community Manager
3108 344 889

This is an accepted solution.

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
    }
  }
}
 
Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 3 (3)

Liam
Community Manager
3108 344 889

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,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Liam
Community Manager
3108 344 889

This is an accepted solution.

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
    }
  }
}
 
Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

appdev2023
Shopify Partner
21 2 3

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