cube-js/cube · error

Unknown query type

Error message

Unknown query type

What it means

The ResultSet constructor reads queryType from the load response (defaulting to REGULAR_QUERY when absent) and validates it against the QUERY_TYPE enum values ('regular', 'compareDateRange', 'blending'). If queryType is set but not one of these, it throws 'Unknown query type'. This guards against constructing a ResultSet from a corrupted, hand-crafted, or version-mismatched load response.

Source

Thrown at packages/cubejs-client-core/src/ResultSet.ts:132

  public constructor(loadResponse: LoadResponse<T> | LoadResponseResult<T>, options: ResultSetOptions = {}) {
    if ('queryType' in loadResponse && loadResponse.queryType != null) {
      this.loadResponse = loadResponse;
      this.queryType = loadResponse.queryType;
      this.loadResponses = loadResponse.results;
    } else {
      this.queryType = QUERY_TYPE.REGULAR_QUERY;
      this.loadResponse = {
        ...loadResponse,
        pivotQuery: {
          ...loadResponse.query,
          queryType: this.queryType
        }
      } as LoadResponse<T>;
      this.loadResponses = [loadResponse as LoadResponseResult<T>];
    }

    if (!Object.values(QUERY_TYPE).includes(this.queryType)) {
      throw new Error('Unknown query type');
    }

    this.parseDateMeasures = options.parseDateMeasures;
    this.options = options;

    this.backwardCompatibleData = [];
  }

  /**
   * Returns a measure drill down query.
   *
   * Provided you have a measure with the defined `drillMembers` on the `Orders` cube
   * ```js
   * measures: {
   *   count: {
   *     type: `count`,
   *     drillMembers: [Orders.status, Users.city, count],
   *   },

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Remove the queryType property (or pass a plain load response) so the constructor defaults to REGULAR_QUERY, unless you truly have a compareDateRange/blending response.
  2. Use valid values only: 'regular', 'compareDateRange', 'blending' — or better, let the API response supply it.
  3. Upgrade @cubejs-client-core so its QUERY_TYPE enum matches the server's response format.
  4. Only pass results of resultSet.serialize() to deserialize — not hand-modified JSON.

Example fix

// before
const rs = new ResultSet({ ...loadResponse, queryType: 'regularQuery' }); // throws 'Unknown query type'

// after
const rs = new ResultSet(loadResponse); // queryType omitted -> defaults to REGULAR_QUERY
Defensive patterns

Strategy: validation

Validate before calling

const VALID_QUERY_TYPES = ['regular', 'compareDateRange', 'blending'];
function validateLoadResponse(lr) {
  if ('queryType' in lr && lr.queryType != null && !VALID_QUERY_TYPES.includes(lr.queryType)) {
    throw new Error(`Invalid queryType: ${lr.queryType}`);
  }
  return lr;
}
const rs = new ResultSet(validateLoadResponse(loadResponse));

Type guard

function isKnownQueryType(qt: unknown): qt is 'regular' | 'compareDateRange' | 'blending' {
  return qt == null || ['regular', 'compareDateRange', 'blending'].includes(qt as string);
}

Try / catch

let resultSet;
try {
  resultSet = new ResultSet(loadResponse);
} catch (e) {
  if (e.message === 'Unknown query type') {
    resultSet = new ResultSet({ ...loadResponse, queryType: undefined }); // default to regular
  } else { throw e; }
}

Prevention

When it happens

Trigger: new ResultSet(loadResponse) or ResultSet.deserialize(serialized) where loadResponse.queryType is set but not a valid QUERY_TYPE value — e.g. a newer server emitting an unseen queryType string, a manually assembled object with queryType: 'regularQuery' instead of 'regular', a typo like 'blended', or corrupted JSON after round-tripping.

Common situations: Deserializing stored results that were hand-edited; client/server version mismatch where the server emits a queryType the older client does not know; custom code constructing ResultSet from a raw REST response and guessing the queryType value instead of omitting it.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/cbb4a6fffd887cc6. Report an issue: GitHub.