guards.ts 602 B

123456789101112131415161718192021
  1. import { DataQuery } from '@grafana/data';
  2. import { isExpressionReference } from '@grafana/runtime/src/utils/DataSourceWithBackend';
  3. import { ExpressionQuery, ExpressionQueryType } from './types';
  4. export const isExpressionQuery = (dataQuery?: DataQuery): dataQuery is ExpressionQuery => {
  5. if (!dataQuery) {
  6. return false;
  7. }
  8. if (isExpressionReference(dataQuery.datasource)) {
  9. return true;
  10. }
  11. const expression = dataQuery as ExpressionQuery;
  12. if (typeof expression.type !== 'string') {
  13. return false;
  14. }
  15. return Object.values(ExpressionQueryType).includes(expression.type);
  16. };