I'm using GraphQL shorthand to specify the types in a schema, eg
type Car {
id: ID!
make: String
model: String
description: String
}
Using this shorthand, is there a way to mark a field as deprecated? Say I wanted to mark description as deprecated. Here's my wild guess on how to do this.
type Car {
id: ID!
make: String
model: String
@deprecated
description: String
}
But no dice. Is field deprecation achievable in GraphQL shorthand?
Thanks!
To mark a field as deprecated, we'll use GraphQL schema directives. A schema directive is indicated with an @ character, and it decorates a specific symbol in your schema, such as a type or field definition.
The typical process would be: Remove all references to the item (query, mutation, field, etc) from core code. If the schema item is a field or enum, mark the GraphQL schema item as deprecated using the @deprecated directive.
The conclusion to all of this is a simple statement – no, GraphQL is not made obsolete by HTTP/2.
The __typename field returns the object type's name as a String (e.g., Book or Author ). GraphQL clients use an object's __typename for many purposes, such as to determine which type was returned by a field that can return multiple types (i.e., a union or interface).
Yup, you can mark fields as deprecated like this:
type Car {
id: ID!
make: String
model: String
description: String @deprecated(reason: "Field is deprecated!")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With