nocobase/nocobase · error · FlowSurfaceBadRequestError

chart query.resource is required

Error message

chart query.resource is required

What it means

normalizeMergedChartResource is the top-level resolver for a chart query's collection reference. If the query has neither a resource key nor a collectionPath key and options.required is set, it throws FlowSurfaceBadRequestError 'chart query.resource is required'.

Source

Thrown at packages/plugins/@nocobase/plugin-flow-engine/src/server/flow-surfaces/chart-config.ts:657

    const collectionPathResource = normalizeChartResourceFromCollectionPath(
      query.collectionPath,
      'chart query.collectionPath',
    );
    if (!_.isEqual(resource, collectionPathResource)) {
      throw new FlowSurfaceBadRequestError(
        'chart query.resource and chart query.collectionPath must reference the same collection',
      );
    }
    return resource;
  }
  if (hasOwn(query, 'resource')) {
    return normalizeChartResource(query.resource, 'chart query.resource', options);
  }
  if (hasOwn(query, 'collectionPath')) {
    return normalizeChartResourceFromCollectionPath(query.collectionPath, 'chart query.collectionPath', options);
  }
  if (options.required) {
    throw new FlowSurfaceBadRequestError('chart query.resource is required');
  }
  return undefined;
}

function normalizeChartMeasure(input: any, index: number) {
  const label = `chart query.measures[${index}]`;
  const normalized = ensurePlainObject(input, label);
  const field = normalizeChartQueryFieldPathValue(normalized.field, `${label}.field`, { required: true });
  const alias = normalizeOptionalTrimmedString(normalized.alias, `${label}.alias`);
  const aggregation = normalizeOptionalEnumValue(
    normalized.aggregation,
    CHART_QUERY_AGGREGATION_SET,
    `${label}.aggregation`,
  );
  return buildDefinedObject({
    field,
    aggregation,
    alias: alias || (Array.isArray(field) && field.length > 1 ? aliasOfFieldValue(field) : undefined),

View on GitHub (pinned to fa42722fef)

Solutions

  1. Add query.resource: { collectionName, dataSourceKey? } to the chart query
  2. Or add query.collectionPath: [dataSourceKey, collectionName]
  3. Fix payload nesting so resource/collectionPath sit directly on the query object (hasOwn checks top-level keys only)

Example fix

// before
{ query: { filter: {}, measures: [] } }
// after
{ query: { resource: { collectionName: 'orders', dataSourceKey: 'main' }, filter: {}, measures: [] } }
Defensive patterns

Strategy: validation

Validate before calling

function assertQueryHasCollection(query = {}) {
  const hasResource = Object.prototype.hasOwnProperty.call(query, 'resource') && query.resource != null;
  const hasPath = Object.prototype.hasOwnProperty.call(query, 'collectionPath') && query.collectionPath != null;
  if (!hasResource && !hasPath) throw new Error('chart query.resource is required');
}

Type guard

function hasChartResource(q: unknown): q is { resource: { collectionName: string; dataSourceKey?: string } } {
  return typeof q === 'object' && q !== null && (q as any).resource != null && typeof (q as any).resource.collectionName === 'string';
}

Try / catch

try {
  await api.saveChartQuery(query);
} catch (err) {
  if (err instanceof FlowSurfaceBadRequestError && err.message === 'chart query.resource is required') {
    // open collection selection UI, then attach query.resource and retry
  }
  throw err;
}

Prevention

When it happens

Trigger: Any strictly-normalized chart query operation (creating/updating a chart whose query must target a collection) with a query object lacking both resource and collectionPath.

Common situations: New charts before collection selection; API clients sending bare query bodies; payloads where the fields were nested one level deeper than the schema expects.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of nocobase/nocobase@fa42722fef (2026-09-01). Data as JSON: /api/errors/97d329ba65fe6f21. Report an issue: GitHub.