async query()

in web/timebase-datasource-plugin/src/DataSource.ts [43:110]


  async query(options: DataQueryRequest<MyQuery>): Promise<DataQueryResponse> {
    this.isChangeCurrencyInterval = isChangeInterval(this.currencyInterval, options.range);

    this.currencyInterval = options.range;

    if (options.targets.some((target: any) => target.selectedStream == null)) {
      return { data: [] };
    }

    options.targets = options.targets.map((target: any) => {
      const interval = getInterval(target.selectedInterval, this.isChangeCurrencyInterval);
      if (
        this.isChangeCurrencyInterval &&
        !(
          interval.intervalType === 'MAX_DATA_POINTS' &&
          (isNaN(target.selectedInterval) ||
            this.intervals.find((interval: any) => interval.value === target.selectedInterval) == null)
        )
      ) {
        this.createAlert();
      }

      return {
        refId: target.refId,
        stream: target.selectedStream,
        queryType: 'CUSTOM',
        view: target.requestType == null ? DATAFRAME_KEY : target.requestType,
        symbols:
          target.selectedSymbol != null && target.selectedSymbol !== '' && target.selectedSymbol !== ALL_KEY
            ? [target.selectedSymbol]
            : [],
        hide: target.hide,
        types: [],
        functions: getFunctions(target.selects),
        interval,
        filters: getFilters(target.filters),
        groupBy:
          target.selectedGroups == null
            ? []
            : target.selectedGroups.map((group: string) => {
                const [type, field] = separateTypeAndField(group);
                return { type, name: field };
              }),
        groupByView:
          target.selectedGroups == null ? null : target.selectedOption == null ? 'COLUMN' : target.selectedOption,
      } as any;
    });
    this.intervals = getIntervals(options.maxDataPoints as any, options.range);
    const request$ = this.sendRequest('POST', '/queries/select', options);
    request$
      .then(() => {
        this.queryError = '';
      })
      .catch((er: { data: { message: string } }) => {
        this.queryError = er.data.message;
      });

    return request$.then(result => {
      for (const dataFrame of result.data) {
        if (dataFrame.fields != null) {
          for (const field of dataFrame.fields) {
            field.values = new ArrayVector(field.values);
          }
        }
      }
      return result;
    });
  }