Apollo Server v3 升级到 Apollo Server v4
¥Apollo Server v3 upgraded to Apollo Server v4
Strapi 5 已迁移到 Apollo Server v4,这可能需要一些手动迁移步骤。
¥Strapi 5 has migrated to Apollo Server v4 and this might require some manual migration steps.
此页面是 重大变更数据库 的一部分,提供有关重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的其他说明。
¥This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.
🔌 此重大更改是否会影响插件? | 是 |
---|
🤖 此重大更改是否由 codemod 自动处理? | 否 |
---|
重大更改描述
¥Breaking change description
在 Strapi v4 中
¥In Strapi v4
GraphQL 服务器的 Apollo Server v3 和 GraphQL 模块的 graphql ^15。
¥Apollo Server v3 for the GraphQL server and graphql ^15 for the GraphQL module.
在 Strapi 5 中
¥In Strapi 5
GraphQL 服务器的 Apollo Server v4 和 GraphQL 模块的 graphql ^16。
¥Apollo Server v4 for the GraphQL server and graphql ^16 for the GraphQL module.
迁移
¥Migration
本节重新组合了有关引入的重大更改的有用说明和程序。
¥This section regroups useful notes and procedures about the introduced breaking change.
注意
¥Notes
-
由于 Apollo 在 v4 中引入了重大更改,Strapi 会自动在 Apollo 服务器配置中设置
status400ForVariableCoercionErrors: true
。此行为在 Apollo v5 中将再次成为默认行为。¥Strapi automatically sets
status400ForVariableCoercionErrors: true
in the Apollo Server configuration due to a breaking change introduced by Apollo in v4. This behavior will be the default again in Apollo v5. -
Strapi 5 将 graphql 包从 ^15 升级到 ^16,并且任何项目只能包含一个版本。因此,依赖于 graphql:15 的用户代码或插件需要使用与 Strapi 相同的版本范围。
¥Strapi 5 upgraded the package graphql from ^15 to ^16, and only one version can be included in any project. Therefore, user code or plugins relying on graphql:15 need to use the same version range as Strapi.
-
有关升级到 Apollo Server v4 的指导,请参阅以下手动迁移部分。有关更多详细信息,请参阅 Apollo v4 迁移 文档。
¥For guidance on upgrading to Apollo Server v4, please refer to the following Manual migration section. For more detailed information, consult the Apollo v4 migration documentation.
手动迁移
¥Manual migration
要迁移到 Strapi 5:
¥To migrate to Strapi 5:
-
设置
x-apollo-operation-name
标头或通过在 GraphQL 插件配置中将csrfPrevention: false
添加到 apolloServer 来禁用多部分消息(文件上传)的新保护。¥Set the
x-apollo-operation-name
header or disable the new protection by addingcsrfPrevention: false
to apolloServer in the GraphQL plugin configuration for multipart messages (file uploads). -
将
ApolloError
替换为GraphQLError
。¥Replace
ApolloError
withGraphQLError
. -
删除属性(适用于查询和突变响应):
¥Remove root level configuration options like
formatResponse
and replace them with plugin hooks in the plugins array. -
删除 i18n 插件依赖,因为 i18n 现在已集成到 Strapi 的核心中
¥Remove the modules configuration option and split it into
typeDefs
andresolvers
. -
将
debug
替换为includeStacktraceInErrorResponses
。¥Replace
debug
withincludeStacktraceInErrorResponses
.