SuperAPI AI 工具集

frontend-query-mutation

前端与建站

查看项目

更新于 10-15 23:48

技能介绍

用途:这是 Langflow 前端查询与变更(Query & Mutation)的实现指南,供在 controllers/API/queries/{domain}/ 目录下创建或更新 API hooks 时使用,确保 API hooks 作为有组织的唯一数据来源。\n\n主要能力与约定:数据获取使用 Axios + TanStack React Query v5,不存在 oRPC 或契约层。调用链为:组件 → API hook(controllers/API/queries/{domain}/use-{verb}-{resource}.ts)→ UseRequestProcessor(controllers/API/services/request-processor.ts)→ useQuery/useMutation → queryFn/mutationFn → api.get/post/patch/delete(来自 controllers/API/api.tsx 的 Axios 实例)。所有 REST 的 HTTP 调用必须使用 Axios api 实例,不得使用原生 fetch;流式操作(构建、聊天)使用 performStreamingRequest()。缓存失效放在 mutation 的 onSettled 回调中。\n\n关键文件:controllers/API/api.tsx 提供 Axios 实例、ApiInterceptor 组件与 performStreamingRequest();controllers/API/services/request-processor.ts 提供包装 useQuery/useMutation 的 UseRequestProcessor hook,带默认重试;controllers/API/helpers/constants.ts 提供 URL 常量(URLs)与 getURL();types/api/index.ts 提供 useQueryFunctionType、useMutationFunctionType 类型辅助;stores/ 为 Zustand 客户端状态存储。\n\n使用方式:先确定改动面;阅读 references/query-patterns.md 了解 hook 结构、命名、URL 模式与调用点形态,阅读 references/runtime-rules.md 了解条件查询、失效、错误处理与流式请求,跨 hook 创建和运行时行为时两者都读;随后按既有模式实现。使用 UseRequestProcessor 的 query() 与 mutate() 包装,使用 api 实例发起 HTTP 调用,用 getURL() 构造路径,并以 useQueryFunctionType 或 useMutationFunctionType 标注类型。保持约定:查询键为含 hook 名的数组(如 ["useGetFlows"]);mutation 在 onSettled 中失效相关查询;Zustand store 更新发生在查询/变更函数中而非组件内;UseRequestProcessor 默认查询重试 5 次、变更重试 3 次,采用指数退避。\n\n常改动文件:use-get-.ts、use-post-.ts、use-patch-.ts、use-delete-.ts、helpers/constants.ts、types/api/index.ts 及 stores/。\n\n限制:资料未提供运行环境、安装命令、版本要求、收费与平台信息;实现细节以参考文件为准,不应在项目文档中重复规则。