webiny-cms-bulk-actions
它能做什么
这项技能在你的 AI 为 Webiny CMS 内容列表添加批量操作时提供指导,例如为许多条目统一打折。适合需要一次修改大量条目的开发者。
适用场景
- ✓当你希望在 CMS 条目列表上有一个按钮,可一次修改许多条目的时候。
- ✓当批量修改必须作为后台任务,跨越大量条目运行的时候。
- ✓当批量操作需要按自定义字段筛选条目的时候。
技能链接
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/cms-bulk-actions/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为产品列表添加一个批量操作,为所有选中的条目打折。”
每周 5 个新技能,1 分钟读完。
工作原理
技能讲解一个包含两个步骤的批量操作类:一个步骤选择要加载的条目,另一个步骤修改每个条目。然后 Webiny 自动创建后台任务和 mutation,由管理端按钮触发它们。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Custom Headless CMS bulk actions
TL;DR
A bulk action is a class implementing EntriesBulkAction.Interface with two methods —
loadData (which entries) and processData (what to do to each). Register it with
export default EntriesBulkAction.createImplementation({...}) via <Api.Extension src>.
For every registered bulk action, Webiny automatically generates a list background
task, a process background task, and a GraphQL mutation. On the Admin side, add a
ContentEntryListConfig.Browser.BulkAction button that calls BulkActionFeature's
useCase.execute({ model, action, where, data }).
Available from Webiny 6.5.0 (webiny/api/cms/entry).
Backend — the bulk action
// extensions/myBulkAction/api/MyBulkAction.ts
import {
EntriesBulkAction,
ListLatestEntriesUseCase,
UpdateEntryUseCase
} from "webiny/api/cms/entry";
class MyBulkActionImpl implements EntriesBulkAction.Interface {
// PascalCased into the task ids + GraphQL enum value, so "applyDiscount" →
// tasks hcmsBulk(List|Process)ApplyDiscountEntries and frontend action "ApplyDiscount".
readonly name = "applyDiscount";
// Optional: restrict which models get the mutation/button.
readonly modelIds = ["product"];
// Optional: entries processed per batch (defaults to the configured batchSize).
// readonly batchSize = 50;
constructor(
private listEntries: ListLatestEntriesUseCase.Interface,
private updateEntry: UpdateEntryUseCase.Interface
) {}
// Runs in the "list" task, with pagination (params.where/search/after/limit).
async loadData(model, params) {
const result = await this.listEntries.execute(model, params);
return result.value; // { entries, meta }
}
// Runs in the "process" task, once per entry, in batches.
async processData(model, params) {
// params.id is a revision id ("<entryId>#0001"); params.data carries whatever the
// Admin action sent.
// ...update / transform the entry here...
}
}
export default EntriesBulkAction.createImplementation({
implementation: MyBulkActionImpl,
dependencies: [ListLatestEntriesUseCase, UpdateEntryUseCase]
});
loadData/processData are the background-task body. You never write scheduling,
batching, retry, or timeout-resume code — the tasks system provides all of it. Webiny
generates hcmsBulkList<Name>Entries, hcmsBulkProcess<Name>Entries, and the mutation
bulkAction<SingularApiName>(action: <Name>, ...).
Convergence — the #1 gotcha
The engine calls loadData repeatedly until it returns zero entries — after each
processing round it re-lists to check for more work. If loadData keeps returning the
same entries, the task never converges: it re-processes them until it hits maxIterations
and fails. So the filter MUST exclude already-processed entries.
- State-transition actions converge naturally: Publish filters
status_not: "published"andprocessDatapublishes; the next list is smaller. Built-in actions rely on this. - Actions with no natural "done" state need a marker:
- A boolean flag:
loadDataexcludesflag = true;processDatasets it. Simple, but blocks re-running until you reset the flag. - A per-run token (re-runnable): the Admin action generates a fresh
runIdper click and filters "not stamped with this run";processDatastamps the entry withrunId. The run converges once everything is stamped, but the next click uses a new token, so the same entries are eligible again — no manual reset.
- A boolean flag:
Where filters — two layers, two formats
The bulk-action list path talks to storage directly, bypassing the GraphQL where-transform. Mind the difference:
- GraphQL where (what the Admin action sends, typed as
<Model>ListWhereInput): system fields are top-level (id_in,status_not,savedOn_lt, …); custom fields are nested undervalues—where: { values: { onSale_not: true } }. A dotted key like"values.onSale_not"is rejected by the typed input. - Storage where (what
loadDatapasses to the list use case): custom fields are flat dotted —{ "values.onSale_not": true }; system fields stay top-level. A bareonSale_notthrowsThere is no field with the fieldId "onSale".
So if the Admin action sends a custom-field filter, flatten it in loadData:
async loadData(model, params) {
const where = { ...params.where };
if (where.values && typeof where.values === "object") {
常见问题
需要哪个 Webiny 版本?
技能说明,批量操作从 Webiny 6.5.0 开始可用。
由谁决定哪些条目被修改?
loadData 步骤选择条目,processData 修改每一个条目。
它也涵盖管理端按钮吗?
涵盖。技能说明了调用该批量操作的管理端按钮。
详情
作者的原始描述
Authoring a custom Headless CMS bulk action (EntriesBulkAction) that Webiny runs as a background task, plus the Admin-side button that triggers it. Use this skill when the developer wants to add a bulk action to the content-entry list (e.g. apply a discount, generate content, bulk-transform entries), understand loadData/processData, make the task converge, filter by custom fields, or trigger the action from the Admin UI. Requires Webiny 6.5.0 or newer.
repo: webiny/webiny-js
热度
- GitHub 星标
- 8.1k
- 排名
- #12584
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
prd-to-plan
8.1k帮你的智能体把产品需求文档转化为分阶段的计划,由许多小的端到端切片组成,并保存为 Markdown 文件。
webiny-admin-architect
8.1k教你的智能体如何为 Webiny 平台构建管理界面,使用其业务逻辑层和呈现器模式。
webiny-admin-permissions
8.1k教你的智能体为 Webiny 管理界面添加权限控制,包括自动生成的权限表单以及显示或隐藏检查。
webiny-form-model
8.1k教你的智能体使用声明式字段构建器、布局、校验和条件规则,在 Webiny 中构建表单。