-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
44 lines (39 loc) · 1.04 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
const queryString = require('querystring');
const createNodeHelpers = require('gatsby-node-helpers').default;
const eventbrite = require('eventbrite').default;
const {
createNodeFactory,
} = createNodeHelpers({
typePrefix: `Eventbrite`,
})
const EventNode = createNodeFactory('Event', node => {
// HACK: since types are inferred we need to mock them or queries fail
node.venue = node.venue || {
id: '',
name: '',
address: {
localized_address_display: '',
},
};
return node
})
exports.sourceNodes = async function(
{ actions: { createNode, setPluginStatus } },
{ query, token }
) {
if (!token) {
throw new Error('Missing Eventbrite OAuth token');
}
const sdk = eventbrite({ token });
try {
const { events } = await sdk.request(
`/events/search/?${queryString.stringify(query)}`
);
events
.map((event) => EventNode(event))
.forEach((eventNode) => createNode(eventNode));
setPluginStatus({lastFetched: new Date()});
} catch (err) {
console.error('EB Fetch fail:', err);
}
};