Expand @deprecated to Objects
At a glance​
- Identifier: #997
- Stage: RFC1: Proposal
- Champion: @fotoetienne
- PR: Expand @deprecated to Objects
Timeline​
- Added to 2024-11-07 WG agenda
- Added to 2023-06-01 WG agenda
- Mentioned in 2023-06 WG notes
- Added to 2022-11 WG agenda
- Mentioned in 2022-11 WG notes
- Commit pushed: Add includeDeprecated argument to __type.possibleTypes on 2022-10-21 by @fotoetienne
- Spec PR created on 2022-10-20 by fotoetienne
- Commit pushed: Expand @deprecated to Objects on 2022-10-20 by @fotoetienne
- Added to 2022-10 WG agenda
Problem
Take as a motivating example:
type Query {
animals: [Animal]
}
interface Animal {
name: String
}
type Dog implements Animal {
name: String
}
type Baiji implements Animal {
name: String
}The Baiji type corresponds to an Animal that is no longer known to exist, and the server will no longer return this type. We would like to delete the code for this type and eventually remove from the schema, but first clients must remove all references of this type from their queries. Currently, there is no good way to indicate to clients that they should no longer spread on this type in their queries.
Solution
Allow @deprecated on objects. Marking as deprecated indicates to clients that this type will no longer be returned from the server. This can indicate to client build tooling that references to this object should be removed from client queries.
type Baiji implements Animal @deprecated {
name: String
}Alternative Solutions​
The most compelling use-case for deprecating types is when they are union members or interface implementations. A potential alternative would be to instead deprecate the membership/implementation instead of the type itself. The main challenge with this approach is with syntax, since it unclear how one would unambiguously annotate an interface implementation using the current
@deprecated
directive. Some possible alternatives:New directive location - @deprecated on UNION_MEMBER
union Animal = Dog | Cat | Baiji @deprecated
New directive @deprecatedMembers on UNION
union Animal @deprecatedMembers(members: ["Baiji"]) = Dog | Cat | Baiji
New directive @deprecatedImplementations on OBJECT
type Baiji implements Node & Animal @deprecatedImplementations(implementations: ["Animal"]) {
id: ID!
name: String
}New directive @deprecatedImplementations on INTERFACE
interface Animal @deprecatedImplementations(implementations: ["Baiji"]) {
id: ID!
name: String
}