In the previous post, we have seen how to check a valid email address using @email directive.
Now we will see how to mark fields as deprecated using @deprecated directive.
Again a brief info on Hypi Directives:
- Hypi directives help to customise the behaviour of the data fields.
-
@
character depicts the Hypi directive. It is followed by a series of characters. - A directive may have a list of optional named arguments.
- Disable directive by adding
#
in front of it.
Let’s check the @deprecated directive!
directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE`
- Use the
@deprecated
directive to mark a field which is no longer required. - A
reason
for deprecation has to be included. - Use Markdown syntax to format the reason.
- If you use the field in any query, the field gets highlighted with a popped up message having the reason for deprecation.
In the below example, field1
has been marked as deprecated.
type DirectiveObj {
field1 : Int @deprecated(reason: "No longer used")
}