@@ -2,13 +2,19 @@ const MapboxClient = require('@mapbox/mapbox-sdk')
2
2
const { chunk } = require ( 'lodash' )
3
3
4
4
const locationForProfile = ( profile ) => {
5
- return profile . location ?
6
- { q : profile . location , types : [ 'place' , 'region' , 'country' ] } :
7
- { q : profile . country , types : [ 'country' ] }
5
+ return profile . location
6
+ ? { q : profile . location , types : [ 'place' , 'region' , 'country' ] }
7
+ : { q : profile . country , types : [ 'country' ] }
8
8
}
9
9
10
10
const sourceNodes = async ( options , pluginOptions ) => {
11
- const { actions : { createNode } , createNodeId, createContentDigest, getNodes, reporter } = options
11
+ const {
12
+ actions : { createNode } ,
13
+ createNodeId,
14
+ createContentDigest,
15
+ getNodes,
16
+ reporter,
17
+ } = options
12
18
const { mapboxToken } = pluginOptions
13
19
14
20
if ( ! mapboxToken ) {
@@ -23,12 +29,13 @@ const sourceNodes = async (options, pluginOptions) => {
23
29
// Implement the filter below to guarantee we're not processing profiles that don't have a team
24
30
25
31
const profiles = getNodes ( )
26
- . filter ( node =>
27
- node . internal . type === 'SqueakProfile' && // For all Squeak profiles
28
- node . teams ?. data ?. length > 0 && // Implement the following to avoid old profiles: filter: { teams: { data: { elemMatch: { id: { ne: null } } } } }
29
- ( node . location || node . country ) // Only process profiles with a location or country
32
+ . filter (
33
+ ( node ) =>
34
+ node . internal . type === 'SqueakProfile' && // For all Squeak profiles
35
+ node . teams ?. data ?. length > 0 && // Implement the following to avoid old profiles: filter: { teams: { data: { elemMatch: { id: { ne: null } } } } }
36
+ ( node . location || node . country ) // Only process profiles with a location or country
30
37
)
31
- . map ( node => ( {
38
+ . map ( ( node ) => ( {
32
39
id : node . id ,
33
40
location : node . location ,
34
41
country : node . country ,
@@ -45,11 +52,13 @@ const sourceNodes = async (options, pluginOptions) => {
45
52
reporter . info ( `Processing batch ${ index + 1 } /${ batches . length } ` )
46
53
47
54
try {
48
- const response = await mapboxClient . createRequest ( {
49
- method : 'POST' ,
50
- path : '/search/geocode/v6/batch' ,
51
- body : batch . map ( locationForProfile )
52
- } ) . send ( )
55
+ const response = await mapboxClient
56
+ . createRequest ( {
57
+ method : 'POST' ,
58
+ path : '/search/geocode/v6/batch' ,
59
+ body : batch . map ( locationForProfile ) ,
60
+ } )
61
+ . send ( )
53
62
54
63
console . log ( JSON . stringify ( response . body . batch , null , 2 ) )
55
64
@@ -63,8 +72,8 @@ const sourceNodes = async (options, pluginOptions) => {
63
72
location : locationForProfile ( batch [ i ] ) . q ,
64
73
coordinates : {
65
74
latitude,
66
- longitude
67
- }
75
+ longitude,
76
+ } ,
68
77
} )
69
78
}
70
79
}
@@ -77,7 +86,7 @@ const sourceNodes = async (options, pluginOptions) => {
77
86
reporter . info ( `Successfully processed ${ locations . length } locations` )
78
87
79
88
// Create nodes directly here, not in a separate function
80
- locations . forEach ( location => {
89
+ locations . forEach ( ( location ) => {
81
90
const nodeContent = {
82
91
...location ,
83
92
}
@@ -114,4 +123,4 @@ const createSchemaCustomization = ({ actions }) => {
114
123
createTypes ( typeDefs )
115
124
}
116
125
117
- module . exports = { sourceNodes, createSchemaCustomization }
126
+ module . exports = { sourceNodes, createSchemaCustomization }
0 commit comments