Queries
Every graphQL query starts from a root node. To see all the available root node you can use, see the Shopify documentation.

Query root

You can query as many root nodes as you want. For example, the following query requests the shop object, a few fields, and the customers connection in a single request.
1
const query = `query {
2
shop {
3
id
4
name
5
email
6
}
7
customers(first:1) {
8
edges {
9
node {
10
id
11
displayName
12
phone
13
}
14
}
15
}
16
}`;
17
const resp = await shopify.graphql(query);
18
// console.log(resp)
19
/*
20
{
21
shop: {
22
id: 'gid://shopify/Shop/xxxxx',
23
name: 'xxxx',
24
email: 'xxxx'
25
},
26
"customers": {
27
"edges": [
28
{
29
"node": {
30
"id": "gid://shopify/Customer/xxx",
31
"displayName": "xxx",
32
"phone": null
33
}
34
}
35
]
36
}
37
}
38
*/
Copied!

Fetching specific ID

You can also pass in specific ID to fetch the resource
1
var query = `query {
2
product(id: "${gql_product_id}") {
3
id
4
vendor
5
}
6
}`;
7
​
8
var productResult = await shopify.graphql(query);
Copied!

Fetching list of ids

1
const gql_variantIDs = JSON.stringify(
2
variantIDs.map(id => `gid://shopify/ProductVariant/${id}`),
3
);
4
​
5
const query = `
6
query {
7
nodes(ids: ${gql_variantIDs}) {
8
...on ProductVariant {
9
id
10
legacyResourceId
11
sku
12
product {
13
id
14
legacyResourceId
15
title
16
tags
17
}
18
}
19
}
20
}`;
21
const { nodes } = await shopify.graphql(query);
Copied!