-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
42 lines (37 loc) · 1.07 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const spree = require('@spree/storefront-api-v2-sdk/dist/server')
exports.sourceNodes = async({
actions: {
createNode
},
createNodeId,
createContentDigest
}, {host}) => {
const {makeClient} = spree;
const client = makeClient({host});
const productsFetch = await client
.products
.list();
const {success} = productsFetch;
const products = success();
const processProducts = product => {
const nodeId = createNodeId(`spree-product-${product.id}`);
const nodeContent = JSON.stringify(product);
const nodeData = Object.assign({}, product, {
id: nodeId,
parent: null,
children: [],
internal: {
type: `SpreeProducts`,
mediaType: `application/javascript`,
content: nodeContent,
contentDigest: createContentDigest(product)
}
});
return nodeData
}
products
.data
.forEach(product => {
createNode(processProducts(product))
});
};