@@ -68,10 +68,10 @@ type ItineraryResponse = {
68
68
data : Record <
69
69
string ,
70
70
{
71
- itineraries : {
72
- legs : {
73
- distance : number
74
- } [ ]
71
+ edges : {
72
+ node : {
73
+ walkDistance : number
74
+ }
75
75
} [ ]
76
76
}
77
77
>
@@ -112,25 +112,43 @@ export async function fetchUnitsWithDistances(
112
112
${ unitsToQuery
113
113
. map (
114
114
( { id, location } ) => `
115
- ${ uuidToKey ( id ) } : plan(
116
- from: {
117
- lat: ${ startLocation . lat } ,
118
- lon: ${ startLocation . lon }
119
- },
120
- to: {
121
- lat: ${ location ?. lat ?? 0 } ,
122
- lon: ${ location ?. lon ?? 0 }
123
- },
124
- modes: "WALK"
125
- ) {
126
- itineraries{
127
- legs {
128
- distance
115
+ ${ uuidToKey ( id ) } : planConnection(
116
+ origin: {
117
+ location: {
118
+ coordinate: {
119
+ latitude: ${ startLocation . lat }
120
+ longitude: ${ startLocation . lon }
129
121
}
130
122
}
131
123
}
124
+ destination: {
125
+ location: {
126
+ coordinate: {
127
+ latitude: ${ location ?. lat ?? 0 }
128
+ longitude: ${ location ?. lon ?? 0 }
129
+ }
130
+ }
131
+ }
132
+ modes: {
133
+ direct: WALK
134
+ directOnly: true
135
+ }
136
+ preferences: {
137
+ street: {
138
+ walk: {
139
+ speed: 300
140
+ }
141
+ }
142
+ }
143
+ ) {
144
+ edges {
145
+ node {
146
+ walkDistance
147
+ }
148
+ }
149
+ }
132
150
133
- `
151
+ `
134
152
)
135
153
. join ( '' ) }
136
154
}`
@@ -156,18 +174,14 @@ export async function fetchUnitsWithDistances(
156
174
drivingDistance : null
157
175
}
158
176
159
- const itineraries = plan . itineraries
160
- if ( itineraries . length === 0 )
177
+ const edges = plan . edges
178
+ if ( edges . length === 0 )
161
179
return {
162
180
...unit ,
163
181
drivingDistance : null
164
182
}
165
183
166
- const itinerary = itineraries [ 0 ]
167
- const drivingDistance = itinerary . legs . reduce (
168
- ( acc , leg ) => acc + leg . distance ,
169
- 0
170
- )
184
+ const drivingDistance = edges [ 0 ] . node . walkDistance
171
185
return {
172
186
...unit ,
173
187
drivingDistance
@@ -182,23 +196,41 @@ export const fetchDistance = async (
182
196
) : Promise < number > => {
183
197
const query = `
184
198
{
185
- plan(
186
- from: {
187
- lat: ${ startLocation . lat } ,
188
- lon: ${ startLocation . lon }
189
- },
190
- to: {
191
- lat: ${ endLocation . lat } ,
192
- lon: ${ endLocation . lon }
193
- },
194
- modes: "WALK"
195
- ) {
196
- itineraries{
197
- legs {
198
- distance
199
+ planConnection(
200
+ origin: {
201
+ location: {
202
+ coordinate: {
203
+ latitude: ${ startLocation . lat }
204
+ longitude: ${ startLocation . lon }
205
+ }
206
+ }
207
+ }
208
+ destination: {
209
+ location: {
210
+ coordinate: {
211
+ latitude: ${ endLocation . lat }
212
+ longitude: ${ endLocation . lon }
213
+ }
214
+ }
215
+ }
216
+ modes: {
217
+ direct: WALK
218
+ directOnly: true
219
+ }
220
+ preferences: {
221
+ street: {
222
+ walk: {
223
+ speed: 300
199
224
}
200
225
}
201
226
}
227
+ ) {
228
+ edges {
229
+ node {
230
+ walkDistance
231
+ }
232
+ }
233
+ }
202
234
}`
203
235
204
236
return axios
@@ -214,12 +246,12 @@ export const fetchDistance = async (
214
246
}
215
247
)
216
248
. then ( ( res ) => {
217
- const plan = res . data . data . plan
218
- if ( ! plan ) throw Error ( 'No plan found' )
249
+ const planConnection = res . data . data . planConnection
250
+ if ( ! planConnection ) throw Error ( 'No planConnection found' )
219
251
220
- const itineraries = plan . itineraries
221
- if ( itineraries . length === 0 ) throw Error ( 'No itineraries found' )
252
+ const edges = planConnection . edges
253
+ if ( edges . length === 0 ) throw Error ( 'No edges found' )
222
254
223
- return itineraries [ 0 ] . legs . reduce ( ( acc , leg ) => acc + leg . distance , 0 )
255
+ return edges [ 0 ] . node . walkDistance
224
256
} )
225
257
}
0 commit comments