import { QueryService } from './base'; import { DirectQueryService } from './direct'; import { GrafanaQueryService } from './grafana'; import { QueryType } from '../../connectors'; import { QueryConfig } from '../../models/query_config'; export function queryServiceFactory( queryConfig: QueryConfig, ): QueryService { const classMap = { [QueryType.DIRECT]: DirectQueryService, [QueryType.GRAFANA]: GrafanaQueryService, }; const queryType = queryConfig.queryType; const datasource = queryConfig.datasource; if(classMap[queryType] === undefined) { console.error(`Queries of type ${queryType} are not supported currently`); throw new Error(`Queries of type ${queryType} are not supported currently`); } else { return new classMap[queryType](datasource); } }