在不同的突变中使用相同对象的输入类型

Using input types of the same object in different mutations

我有一个输入类型,我想在多个突变中使用。从一种突变到另一种突变的使用之间的唯一区别是其字段的强制性 属性。

例如,假设我在创建变更中使用了以下输入类型:

input ObjectInput {
  name: String!
  description: String!
}

namedescription 字段都是必填字段。

如果我想在 description 是可选的另一个突变中使用相同的输入类型怎么办?我真的必须创建另一个输入类型来消除字段的强制性 属性 吗?

Do I really have to create another input type just to eliminate the mandatory property of the field?

是的。

如果之间有多个共同字段(相同的名称,完全相同的类型),那么您可以将其分解为一个单独的类型,嵌入到您的输入对象类型中;

input ObjectIdentity {
  name: String!
}
input ObjectInput {
  identity: ObjectIdentity!
  description: String!
}

但这会以您不希望的方式更改对象格式(添加额外的 "identity" 对象字段)。