-
Notifications
You must be signed in to change notification settings - Fork 10
/
gatsby-node.js
35 lines (30 loc) · 892 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 queryDb = require('./src/db');
const createMysqlNodes = require('./src/create-mysql-nodes');
exports.sourceNodes = async (
{ actions, store, createNodeId, cache, reporter },
configOptions
) => {
const { createNode } = actions;
const { connectionDetails, queries } = configOptions;
const { db, queryResults } = await queryDb(connectionDetails, queries, reporter);
try {
const sqlData = queries.map((query, index) =>
Object.assign({}, query, { __sqlResult: queryResults[index] })
);
await Promise.all(
sqlData.map((sqlResult, _, sqlResults) =>
createMysqlNodes(sqlResult, sqlResults, {
createNode,
store,
createNodeId,
cache,
reporter
})
)
);
db.end();
} catch (e) {
reporter.error(`Error while sourcing data with gatsby-source-mysql`, e);
db.end();
}
};