-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
44 lines (38 loc) · 1.03 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
43
44
const path = require('path');
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
},
});
};
//We use Gatsby-node to generate pages
//Because it is node, we have to resolve, we can't just use an import
//graphql Object allows us to query our data through graphql
//actions Object uses redux
exports.createPages = async ({graphql, actions}) => {
const {createPage} = actions;
//data Objext has access to all the Shopify data
const {data} = await graphql(`
{
allShopifyProduct {
edges {
node {
shopifyId
handle
}
}
}
}
`);
data.allShopifyProduct.edges.forEach(({node}) => {
createPage({
path: `products/${node.handle}`,
context: {
//Gatsby will inject the context into the props of the ProductTemplate Component
shopifyId: node.shopifyId,
},
component: path.resolve('./src/templates/ProductTemplate/index.js')
});
});
};