import firebase from 'firebase/app' ; import { parseObjectValue } from './firegraph/Where' ; import { resolveCollection } from './firegraph/Collection' ; import { FiregraphResult } from './types/Firegraph' ; import { CacheManager } from './firegraph/CacheManager' ; param firestore param query async function resolve ( firestore , query ) { const results = { } ; const { definitions } = query ; const cacheManager = new CacheManager ( ) ; for ( let definition of definitions ) { const { selectionSet } = definition ; const targetCollections = selectionSet . selections ; for ( let collection of targetCollections ) { const { name : { value : collectionName } , alias : alias , selectionSet , arguments : collectionArguments , } = collection ; const parsedArgs = { } ; collectionArguments . forEach ( ( arg ) => { if ( arg . value . kind === 'ObjectValue' ) { const { fields } = arg . value ; parsedArgs [ arg . name . value ] = parseObjectValue ( fields ) ; } else { parsedArgs [ arg . name . value ] = arg . value . value ; } } ) ; const result = await resolveCollection ( firestore , collectionName , parsedArgs , selectionSet , cacheManager ) ; if ( alias != undefined ) results [ alias . value ] = result . docs ; else results [ result . name ] = result . docs ; } } return results ; } export default { resolve , } ;