-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
45 lines (40 loc) · 1.23 KB
/
gatsby-node.js
File metadata and controls
45 lines (40 loc) · 1.23 KB
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
// const fetch = require("node-fetch")
exports.sourceNodes = async ({
actions,
createNodeId,
createContentDigest,
}) => {
/*
try {
// Fetch the data
const res = await fetch(`https://api.rawg.io/api/games`)
// Transform the data into json
const data = await res.json()
// Map over the results array, calling action.createNode on each item in the array
data.results.forEach(game => {
const node = {
...game, // We copy all of the properties from the game object
id: createNodeId(`RAWG-game-${game.id}`), // Needs to be unique
internal: {
type: "RAWGGame",
contentDigest: createContentDigest(game), // We pass in the entire game object to make sure it's unique
},
}
// Create the actual data node
actions.createNode(node)
})
} catch (error) {
console.log(error)
}
*/
const newNode = {
title: "Test Node!",
description: "This is a test node with static data",
id: createNodeId("TestNode-testid"), // required by Gatsby
internal: {
type: "TestNode", // required by Gatsby
contentDigest: createContentDigest("testnode"), // required by Gatsby, must be unique
},
}
actions.createNode(newNode)
}