forked from vendure-ecommerce/gatsby-storefront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
41 lines (38 loc) · 1.02 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
const path = require("path");
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
/*// You can delete this file if you're not using it
exports.onCreateNode = ({ node }) => {
console.log(node.internal.type)
}*/
exports.createPages = ({ graphql, actions }) => {
// **Note:** The graphql function call returns a Promise
// see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise for more info
return graphql(`
{
vendure {
products {
items {
id
slug
}
}
}
}
`).then(result => {
result.data.vendure.products.items.forEach(product => {
actions.createPage({
path: "products/" + product.slug,
component: path.resolve(`./src/templates/ProductDetail.tsx`),
context: {
// Data passed to context is available
// in page queries as GraphQL variables.
id: product.id,
},
});
});
});
};