Hi there,
Fairly new to GraphQL in general, very experienced with the admin REST API. If I'm developing an app in which I want to be able to select products from the default /admin/products and perform a bulk action (being passed an array of IDs from Shopify to my app) can I make one single request in GraphQL with an array of IDs? I searched the docs and forums up and down and don't see a way to do it. Do I need to make a new request for every single product? (If so, seems to defeat the purpose of making less requests!)
Thanks!
Okay, kind of answered my own question: aliases.
Example:
{
product1: product(id: "gid://shopify/Product/1343489802342") {
title
}
product2: product(id: "gid://shopify/Product/1343489835110") {
title
}
}
but let's say I have 30 products. Surely there is a way to dynamically create this query instead of specifying product1, product2, ...., product30
What would be the best method to do this? If I'm using JavaScript, should I just generate the query from JavaScript? Or is there a GraphQL way of doing this?
Thanks!
Hi Rick!
Another option is the nodes field on QueryRoot, which takes an array of ids.
{
nodes(ids: ["gid://shopify/Product/123", "gid://shopify/Product/456"]) {
...on Product {
title
}
}
}
Would this be possible to do with handle as well? I have 10 handles for products and 10 handles for collections, can I somehow group them into an efficient query? I need to get the collection titles / image and product titles / image from grahpql
I've noticed that this "guid" string has to be base64 encoded for it to work with the Storefront API
"gid://shopify/Product/456" --> Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzQ1Ng==
This can be accomplished with the Javascript btoa() function - https://www.w3schools.com/jsref/met_win_btoa.asp
query test($ids: [ID!]!) {
nodes(ids: $ids) {
... on Product {
id
variants(first: 100) {
edges {
node {
title
}
}
}
}
}
}
{
"ids": ["gid://shopify/Product/4406002679856","gid://shopify/Product/4567473815600"]
}
User | Count |
---|---|
13 | |
12 | |
10 | |
8 | |
7 |