-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gatsby-node.js
48 lines (42 loc) · 945 Bytes
/
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
45
46
47
48
const path = require("path")
const PRODUCTS_QUERY = `
query {
allProductsYaml {
nodes {
slug
}
}
}
`
exports.createResolvers = ({ createResolvers }) => {
const resolvers = {
ProductsYamlVariants: {
formattedPrice: {
type: `String`,
resolve: ({ price }) =>
price
? new Intl.NumberFormat("en-US", {
style: "currency",
currency: "usd",
}).format(price / 100)
: null,
},
},
}
createResolvers(resolvers)
}
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const {
data: {
allProductsYaml: { nodes: products },
},
} = await graphql(PRODUCTS_QUERY)
products.forEach(({ slug }) =>
createPage({
component: path.resolve("./src/templates/ProductPage.js"),
context: { slug },
path: `/products/${slug}`,
})
)
}