-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
59 lines (44 loc) · 1.29 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fetch = require('node-fetch');
const NODE_TYPE = 'Pokemon';
exports.sourceNodes = async ({ actions, createNodeId, createContentDigest }) => {
const { createNode } = actions;
// --------------------
const response = await fetch(
"https://api.pokemontcg.io/v1/cards"
);
const { cards = [] } = await response.json();
// const { cards = [] } = json;
// const pokemon = await Promise.all(
// cards.map(async (result) => {
// const pokeResponse = await result;
// return await pokeResponse.json();;
// })
// );
// ------------------
// const response = await fetch(
// "https://pokeapi.co/api/v2/pokemon/"
// );
// const json = await response.json();
// const { results = [] } = json;
// const pokemon = await Promise.all(
// results.map(async (result) => {
// const { url } = result;
// const pokeResponse = await fetch(url);
// return await pokeResponse.json();
// })
// );
// ---------------------
cards.forEach((node, index) => {
createNode({
...node,
id: createNodeId(`${NODE_TYPE}-${node.id}`),
parent: null,
children: [],
internal: {
type: NODE_TYPE,
content: JSON.stringify(node),
contentDigest: createContentDigest(node)
}
})
})
}