-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
35 lines (31 loc) · 912 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
const fetch = require("node-fetch");
exports.sourceNodes = (
{ actions, createNodeId, createContentDigest },
configOptions
) => {
delete configOptions.plugins; // eslint-disable-line no-param-reassign
const { appId } = configOptions;
function createNode(properties) {
return actions.createNode({
...properties,
id: createNodeId(`open-exchange-rates-${properties.currency}`),
parent: null,
children: [],
internal: {
type: "OpenExchangeRates",
content: JSON.stringify(properties),
contentDigest: createContentDigest(properties)
}
});
}
return fetch(`https://openexchangerates.org/api/latest.json?app_id=${appId}`)
.then(response => response.json())
.then(data =>
Object.keys(data.rates).forEach(currency =>
createNode({
currency,
rate: data.rates[currency]
})
)
);
};