-
Notifications
You must be signed in to change notification settings - Fork 7
/
gatsby-node.js
46 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
45
46
const Airtable = require('airtable')
const crypto = require(`crypto`)
exports.sourceNodes = async ({ boundActionCreators },
{apiKey, baseId, tableName, tableView, queryName}) => {
const { createNode, setPluginStatus } = boundActionCreators
const base = new Airtable({
apiKey,
}).base(baseId);
const table = base(tableName);
const query = await table.select({
view: tableView,
})
console.time(`fetch all Airtable rows`)
const all = await query.all();
console.timeEnd(`fetch all Airtable rows`)
setPluginStatus({
status: {
lastFetched: new Date().toJSON(),
},
})
all.forEach(row => {
const gatsbyNode = Object.assign({
// Required Gatsby fields
id: `${row.id}`,
parent: "__SOURCE__",
children: [],
internal: {
type: `Airtable${queryName}`,
contentDigest: crypto
.createHash("md5")
.update(JSON.stringify(row))
.digest("hex")
}
}, row.fields);
createNode(gatsbyNode);
});
return
}