实体服务已弃用
¥Entity Service deprecated
Strapi v4 中使用的实体服务已被弃用,并由 Strapi 5 中的新 文档服务 API 取代。
本节重新组合了有关引入的重大更改的有用说明和程序。
¥This section regroups useful notes and procedures about the introduced breaking change.
¥The Entity Service that was used in Strapi v4 is deprecated and replaced by the new Document Service API in Strapi 5.
本节重新组合了有关引入的重大更改的有用说明和程序。
¥This section regroups useful notes and procedures about the introduced breaking change.
| 🔌 此重大更改是否会影响插件? | 是 |
|---|
| 🤖 此重大更改是否由 codemod 自动处理? | 部分 |
|---|
重大更改描述
¥Breaking change description
在 Strapi v4 中
¥In Strapi v4
实体服务 API 是用于与你的内容类型交互的首选 API。
¥The Entity Service API is the go-to API to use to interact with your content-types.
在 Strapi 5 中
¥In Strapi 5
文档服务 API 取代了 Strapi v4 中的实体服务 API。
¥The Document Service API replaces the Entity Service API from Strapi v4.
迁移
¥Migration
本节重新组合了有关引入的重大更改的有用说明和程序。
¥This section regroups useful notes and procedures about the introduced breaking change.
注意
¥Notes
以下是使用文档服务 API 而不是 Strapi v4 中的实体服务 API 时需要考虑的主要主题:
¥The following are the main topics to take into account when using the Document Service API instead of the Entity Service API from Strapi v4:
-
文档服务 API 需要
documentId属性。
此重大更改还会影响 REST 和 GraphQL API( 参见 相关的重大变更条目)。为了简化向 Strapi 5 的过渡,文档服务 API 响应除了新的documentId字段外,还包含id字段。:::¥The Document Service API expects a
documentIdproperty.
This breaking change also affects the REST and GraphQL APIs ( see the related breaking change entry).InfoTo ease the transition to Strapi 5, Document Service API responses still include
idfields in addition to the newdocumentIdfields. -
Strapi v4 和 Strapi 5 中
findMany()函数返回的响应不同:¥The response returned by the
findMany()function is different in Strapi v4 and Strapi 5:
在 Strapi v4 中:
¥In Strapi v4:
Entity Service API 中的 findMany() 函数为单一类型返回单个项目。
¥The findMany() function from the Entity Service API returns a single item for single types.
在 Strapi 5 中:
¥In Strapi 5:
文档服务中的 findMany() 功能 API 始终返回数组。
要获取单个项目,请从返回的数组中提取第一个项目,或使用 findFirst() 函数。
¥The findMany() function from the Document Service API always returns arrays.
To get a single item, extract the first item from the returned array, or use the findFirst() function.
-
Strapi 5 中不再有
findPage()方法。
参见 相关的重大变更条目。¥There is no
findPage()method anymore in Strapi 5.
see the related breaking change entry. -
起草并发布 功能已在 Strapi 5 中更新,这反映在文档服务 API 中:
¥The Draft & Publish feature has been updated in Strapi 5 and this is reflected in the Document Service API:
-
publicationState被status替换
参见 相关的重大变更条目。¥
publicationStateis replaced bystatus
see the related breaking change entry. -
引入了新方法来处理更新的 起草并发布 功能:
¥New methods are introduced to handle the updated Draft & Publish feature:
-
¥and
discardDraft().
-
published_at属性不能再用于触发内容发布。¥The
published_atproperty can not be used anymore to trigger the publication of content.
-
-
Document Service API 的
delete()功能 返回受影响条目的列表(可以一次删除多个语言环境),而 Strapi v4 中的delete()函数仅返回已删除的条目。¥The
delete()function of the Document Service API returns a list of affected entries (multiple locales can be deleted all at once), while thedelete()function from Strapi v4 returns only the deleted entry. -
实体服务装饰器不再可用,必须改用 文档服务中间件。
¥Entity Service decorators can not be used anymore, and Document Service middlewares must be used instead.
-
文档服务 API 不支持文件上传。
¥The Document Service API does not support file uploads.
迁移程序
¥Migration procedure
使用 升级工具 时,迁移部分由 codemod 处理。
¥The migration is partially handled by a codemod when using the upgrade tool.
实体服务 API 到文档服务 API 迁移参考 提供了有关 codemod 处理哪些方面以及哪些用例需要手动迁移的更多信息。
¥ The Entity Service API to Document Service API migration reference gives additional information about which aspects are handled by the codemod and which use cases require manual migration.