-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgatsby-node.js
40 lines (39 loc) · 1.27 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
const { fetchFromGithub } = require("./src/helper");
const crypto = require("crypto");
const uuid = require("uuid/v1");
exports.sourceNodes = (
{ actions },
{ token, variables, graphQLQuery, url }
) => {
const { createNode } = actions;
return new Promise((resolve, reject) => {
// we need a token to use this plugin
if (token === undefined) {
reject("token is undefined");
return;
}
fetchFromGithub(url, token, graphQLQuery, variables).then(result => {
createNode({
data: result.data,
id: result.id || uuid(),
// see https://github.com/ldd/gatsby-source-github-api/issues/19
// provide the raw result to see errors, or other information
rawResult: result,
parent: null,
children: [],
internal: {
type: "GithubData",
contentDigest: crypto
.createHash(`md5`)
.update(JSON.stringify(result))
.digest(`hex`),
// see https://github.com/ldd/gatsby-source-github-api/issues/10
// our node should have an 'application/json' MIME type, but we wish
// transformers to ignore it, so we set its mediaType to text/plain for now
mediaType: "text/plain"
}
});
resolve();
});
});
};