forked from smakosh/gatsby-portfolio-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
68 lines (63 loc) · 1.39 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
60
61
62
63
64
65
66
67
68
const config = require('./data/config')
const { GraphQLClient } = require(`graphql-request`)
exports.sourceNodes = ({ actions, createNodeId, createContentDigest }) => {
const { createNode } = actions
const { githubLogin } = config
return new Promise((resolve, reject) => {
const query = `
query($githubLogin: String!) {
repositoryOwner(login: $githubLogin) {
pinnedRepositories(first: 6) {
edges {
node {
id
name
url
description
stargazers {
totalCount
}
forkCount
languages(first: 2) {
edges {
node {
color
name
}
}
}
}
}
}
}
}
`
const variables = {
githubLogin,
}
const graphqlClient = new GraphQLClient('https://api.github.com/graphql', {
headers: {
Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
},
})
graphqlClient
.request(query, variables)
.then(data => {
data.repositoryOwner.pinnedRepositories.edges.forEach(node => {
const projectNode = {
id: createNodeId(node.node.id),
internal: {
type: `Projects`,
},
parent: null,
children: [],
...node.node,
}
projectNode.internal.contentDigest = createContentDigest(node)
createNode(projectNode)
})
})
.then(resolve)
.catch(reject)
})
}