File tree Expand file tree Collapse file tree 4 files changed +32
-2
lines changed
Expand file tree Collapse file tree 4 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -259,3 +259,7 @@ export enum OperationType {
259259 /** Set areas' sorting index */
260260 orderAreas = 'orderArea'
261261}
262+
263+ export interface BulkAreasGQLQueryInput {
264+ ancestors : string [ ]
265+ }
Original file line number Diff line number Diff line change 1- import { AreaType } from '../../db/AreaTypes'
1+ import { AreaType , BulkAreasGQLQueryInput } from '../../db/AreaTypes'
22import { GQLContext } from '../../types'
33
44const AreaQueries = {
@@ -11,8 +11,13 @@ const AreaQueries = {
1111 countries : async ( _ , params , { dataSources } : GQLContext ) : Promise < AreaType [ ] > => {
1212 const { areas } = dataSources
1313 return await areas . listAllCountries ( )
14- }
14+ } ,
1515
16+ bulkAreas : async ( _ : any , params , { dataSources } : GQLContext ) : Promise < AreaType [ ] > => {
17+ const { areas } = dataSources
18+ const { ancestors } = params as BulkAreasGQLQueryInput
19+ return await areas . bulkDownloadAreas ( ancestors )
20+ }
1621}
1722
1823export default AreaQueries
Original file line number Diff line number Diff line change 11type Query {
22 area (uuid : ID ): Area
33 areas (filter : Filter , sort : Sort ): [Area ]
4+
5+ """
6+ Bulk download an area and its children starting from ancestors paths (inclusive).
7+ To keep payload at a reasonable size ancestors must have at least 2 elements.
8+ """
9+ bulkAreas (ancestors : [String ! ]! ): [Area ]
10+
411 stats : Stats
512 cragsNear (
613 placeId : String
Original file line number Diff line number Diff line change 1+ import { GraphQLError } from 'graphql'
2+ import { ApolloServerErrorCode } from '@apollo/server/errors'
13import { MongoDataSource } from 'apollo-datasource-mongodb'
24import { Filter } from 'mongodb'
35import muuid from 'uuid-mongodb'
@@ -275,4 +277,16 @@ export default class AreaDataSource extends MongoDataSource<AreaType> {
275277 }
276278 return await this . areaModel . find ( filter ) . lean ( )
277279 }
280+
281+ async bulkDownloadAreas ( ancestors : string [ ] ) : Promise < AreaType [ ] > {
282+ if ( ancestors . length < 2 ) {
283+ throw new GraphQLError ( 'Must provide at least 2 ancestors.' , {
284+ extensions : {
285+ code : ApolloServerErrorCode . BAD_USER_INPUT
286+ }
287+ } )
288+ }
289+ const ancestorsCSV = ancestors . join ( ',' )
290+ return await this . findDescendantsByPath ( ancestorsCSV )
291+ }
278292}
You can’t perform that action at this time.
0 commit comments