import firebase from 'firebase/app' ; import { GraphQLSelectionSet } from '../types/GraphQL' ; import { FiregraphCollectionResult } from '../types/Firegraph' ; import { resolveDocument } from './Document' ; import { setQueryFilters } from './Where' ; import { setOrders } from './Order' ; import { CacheManager } from './CacheManager' ; param store param collectionName param selectionSet param cacheManager export async function resolveCollection ( store , collectionName , collectionArgs , selectionSet , cacheManager ) { let collectionQuery = store . collection ( collectionName ) ; let collectionResult = { name : collectionName , docs : [ ] , } ; if ( collectionArgs ) { if ( collectionArgs [ 'where' ] ) { const where = collectionArgs [ 'where' ] ; collectionQuery = setQueryFilters ( collectionQuery , where ) ; } if ( collectionArgs [ 'limit' ] ) { const limit = Number . parseInt ( collectionArgs [ 'limit' ] ) ; collectionQuery = collectionQuery . limit ( limit ) ; } if ( collectionArgs [ 'orderBy' ] ) { const orders = collectionArgs [ 'orderBy' ] ; collectionQuery = setOrders ( collectionQuery , orders ) ; } } const collectionSnapshot = await collectionQuery . get ( ) ; if ( selectionSet && selectionSet . selections ) { for ( let doc of collectionSnapshot . docs ) { const documentPath = `${ collectionName }/${ doc . id }` ; collectionResult . docs . push ( await resolveDocument ( store , documentPath , selectionSet , cacheManager ) ) ; } } return collectionResult ; }