-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportJSON.js
More file actions
73 lines (68 loc) · 1.36 KB
/
exportJSON.js
File metadata and controls
73 lines (68 loc) · 1.36 KB
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
69
70
71
72
73
'use strict';
const fs = require('fs');
const { createApolloFetch } = require('apollo-fetch');
const fetch = createApolloFetch({
//uri: 'https://api.theforeignarchitect.com/graphql',
uri: 'http://localhost:3000/graphql',
});
const JSON_DIR = '../frontend-gridsome/src/data';
fetch({
query: `{
buildings {
nodes {
id
name
website
year
address
gfa
gmapsEmbed
gmapsLink
height
lat
lng
typology
architectBuildings {
totalCount
nodes {
architect {
id
name
website
}
}
}
city {
country {
id
iso
name
}
id
name
}
links {
totalCount
nodes {
id
title
url
source {
id
name
website
}
}
}
}
}
}`,
}).then(({ data }) => {
const { buildings } = data;
console.log(`Writing ${buildings.nodes.length} building files to disk...`);
for (const building of buildings.nodes) {
const id = building.id;
fs.writeFileSync(`${JSON_DIR}/building-${id}.json`, JSON.stringify(building));
}
console.log('...done!');
});