2021-11-05 10:12:55 -05:00
|
|
|
import { isExpressionReference } from '@grafana/runtime/src/utils/DataSourceWithBackend';
|
2023-03-06 08:46:55 -06:00
|
|
|
import { DataQuery } from '@grafana/schema';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-05-04 09:31:25 -05:00
|
|
|
import { ExpressionQuery, ExpressionQueryType } from './types';
|
2021-04-21 06:57:17 -05:00
|
|
|
|
|
|
|
export const isExpressionQuery = (dataQuery?: DataQuery): dataQuery is ExpressionQuery => {
|
2021-05-04 09:31:25 -05:00
|
|
|
if (!dataQuery) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-11-05 10:12:55 -05:00
|
|
|
if (isExpressionReference(dataQuery.datasource)) {
|
2021-05-04 09:31:25 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const expression = dataQuery as ExpressionQuery;
|
|
|
|
|
|
|
|
if (typeof expression.type !== 'string') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return Object.values(ExpressionQueryType).includes(expression.type);
|
2021-04-21 06:57:17 -05:00
|
|
|
};
|