简体   繁体   English

是否可以弃用 GraphQL 的突变?

[英]Is it possible to deprecate a mutation on GraphQL?

I have a mutation that we want to deprecate:我有一个我们想要弃用的突变:

updateObject(
  id: String!
  object: ObjectInput!
): Object!

We'd like to change it to:我们想把它改成:

updateObject(
  object: UpdateObjectInput!
): Object!

Where ObjectInput and UpdateObjectInput are:其中 ObjectInput 和 UpdateObjectInput 是:

input ObjectInput {
  product: String!
  isPercentage: Boolean
  amount: Float!
  visibility: ObjectVisibility
  isDiscontinued: Boolean
  expiresAt: String
}

and

input UpdateObjectInput {
  id: String!
  visibility: ObjectVisibility
  isDiscontinued: Boolean
  expiresAt: String
}

Basically, ObjectInput is great for creating Object, but not ideal for updating it.基本上,ObjectInput 非常适合创建 Object,但不适合更新它。

We've tried overloading the mutation or marking the mutation as deprecated, but neither works.我们尝试过重载变异或将变异标记为已弃用,但都不起作用。

The only other solutions we've come up with is to rename the new updateObject mutation to something else, like "newUpdateObject", or to make the id and object fields deprecated and optional and then add a field "updateObject" or something that would take in the new UpdateObjectInput.我们提出的唯一其他解决方案是将新的 updateObject 突变重命名为其他名称,例如“newUpdateObject”,或者使 id 和 object 字段不推荐使用和可选,然后添加一个字段“updateObject”或其他需要的东西在新的 UpdateObjectInput 中。 However, neither of those is optimal.然而,这两者都不是最优的。

Is there another way to accomplish the migration?还有其他方法可以完成迁移吗?

Deprecating a field is cosmetic -- it just introduces metadata that can be used by client tools and can provide additional information about the field without changing the field's description.弃用一个字段是装饰性的——它只是引入了可由客户端工具使用的元数据,并且可以在不更改字段描述的情况下提供有关该字段的附加信息。 When a change to the schema would otherwise be a breaking change, the only way to avoid causing issues for your clients is to introduce new fields and/or arguments.当对架构的更改否则将成为破坏性更改时,避免给客户造成问题的唯一方法是引入新的字段和/或参数。 You've already presented some of your options:您已经提供了一些选项:

  1. Create a new field on the Mutation type在 Mutation 类型上创建一个新字段
updateObject(
  id: String!
  object: ObjectInput!
): Object! @deprecated("Use updateObject2 instead")
updateObject2(
  object: UpdateObjectInput!
): Object!
  1. Create a new argument on the existing field.在现有字段上创建一个新参数。 ONly fields and enum values can be deprecated at this time -- you can't apply the @deprecated to arguments.目前只能弃用字段和枚举值——您不能将@deprecated应用于参数。
updateObject(
  """Don't use. Use object2 instead"""
  id: String!

  """Don't use. Use object2 instead"""
  object: ObjectInput!

  object2: UpdateObjectInput!
): Object!
  1. Version the API.版本 API。 Maintain the existing schema at its current endpoint, but introduce the updated schema at a different endpoint.在其当前端点维护现有架构,但在不同端点引入更新的架构。 Direct your client team(s) to switch to the new endpoint.指导您的客户团队切换到新端点。

  2. Just introduce the breaking changes.只介绍突破性的变化。 It may be possible to coordinate with the client team(s) to deploy the changes to both the server and the client within some acceptable maintenance window.可以与客户端团队协调,在某个可接受的维护窗口内将更改部署到服务器和客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM