From eb96a8fcc8ca0949ccbe515ec56a059a90190138 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 18 Mar 2020 00:12:03 +0100 Subject: [PATCH] @grafana/runtime: Add cancellation of queries to DataSourceWithBackend (#22818) --- .../src/utils/DataSourceWithBackend.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts b/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts index 2b627289828..889ad0c8b85 100644 --- a/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts +++ b/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts @@ -37,13 +37,10 @@ export class DataSourceWithBackend< * Ideally final -- any other implementation may not work as expected */ query(request: DataQueryRequest): Observable { - const { targets, intervalMs, maxDataPoints, range } = request; - - let expressionCount = 0; + const { targets, intervalMs, maxDataPoints, range, requestId } = request; const orgId = config.bootData.user.orgId; const queries = targets.map(q => { if (q.datasource === ExpressionDatasourceID) { - expressionCount++; return { ...q, datasourceId: this.id, @@ -65,7 +62,6 @@ export class DataSourceWithBackend< }); const body: any = { - expressionCount, queries, }; if (range) { @@ -75,10 +71,16 @@ export class DataSourceWithBackend< } const req: Promise = getBackendSrv() - .post('/api/ds/query', body) + .datasourceRequest({ + url: '/api/ds/query', + method: 'POST', + data: body, + requestId, + }) .then((rsp: any) => { - return this.toDataQueryResponse(rsp); + return this.toDataQueryResponse(rsp?.data); }); + return from(req); }