A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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?
Solved! Go to the solution
This is an accepted solution.
node
to find a specific object like;{ node(id: "gid://shopify/SellingPlan/553123862") { id ... on SellingPlan { name } } }
nodes
for multiple ids with an array;{ nodes(ids: ["gid://shopify/SellingPlan/553123862"]) { id ... on SellingPlan { name } } }
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
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
This is an accepted solution.
node
to find a specific object like;{ node(id: "gid://shopify/SellingPlan/553123862") { id ... on SellingPlan { name } } }
nodes
for multiple ids with an array;{ nodes(ids: ["gid://shopify/SellingPlan/553123862"]) { id ... on SellingPlan { name } } }
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
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