弃用 ApolloServer 中的类型

Deprecate a type in ApolloServer

这是弃用 ApolloServer 中字段的模式:

type Car {
  id: ID!
  make: String
  model: String
  description: String @deprecated(reason: "Field is deprecated!")
}

但是,我该如何弃用整个类型 - 例如上面的 Car 类型?

不能弃用类型。只有字段和枚举值可能会被弃用。这显示在 @deprecated 指令的定义中 here:

directive @deprecated(
  reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE

并解释 here(强调我的):

To support the management of backwards compatibility, GraphQL fields and enum values can indicate whether or not they are deprecated (isDeprecated: Boolean) and a description of why it is deprecated (deprecationReason: String).

弃用是为了向客户端指示停止请求已弃用的元素。由于客户端不请求特定类型,仅请求特定字段,因此弃用类型没有任何意义。