Fellow Stranger
Fellow Stranger

Reputation: 34013

Deprecate a type in ApolloServer

This is the pattern to deprecate a field in ApolloServer:

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

However, how do I deprecate a whole type - e.g. the Car type above?

Upvotes: 5

Views: 4703

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84687

Types cannot be deprecated. Only fields and enum values may be deprecated. This is shown in the definition of the @deprecated directive here:

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

and explained here (emphasis mine):

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).

Deprecation is meant to indicate to the client to stop requesting the deprecated elements. Since a client doesn't request a specific type, only specific fields, deprecating a type doesn't really make sense.

Upvotes: 12

Related Questions