Mark deprecated fields or enum values with @deprecated.
Schema governance
GraphQL · Class
GraphQL directives use an @-prefixed name to annotate schemas or operations. They can influence validation or execution and may define arguments plus permitted locations.
A GraphQL directive is schema or operation metadata written with an @ name. Type-system directives annotate schema elements so validation or execution can treat them differently, while executable directives let operations influence query execution.
directive @name(arguments) on LOCATIONdirective @auth(rule: Rule) on FIELD_DEFINITION
enum Rule {
IS_AUTHOR
}
type Post {
authorId: ID!
body: String @auth(rule: IS_AUTHOR)
}This SDL declares an authorization directive, restricts it to field definitions, and applies it to the Post.body field.
Schema governance
Cross-cutting schema behavior
Conditional query results
Directives add metadata or behavior using an @-prefixed name. Type-system directives annotate types, fields, or arguments; executable directives can be used in operations and affect execution.
Follow-up: How would you limit a directive to schema fields? Define it with FIELD_DEFINITION as its allowed location.
A directive definition declares its name, arguments, and permitted locations. For example, @deprecated accepts an optional String reason and can target FIELD_DEFINITION or ENUM_VALUE.
Follow-up: What happens when reason is omitted for @deprecated? Its default text is used: No longer supported.
The built-in @deprecated directive marks schema elements as deprecated. Its nullable reason argument has type String and a default value of No longer supported.
Follow-up: Can the same directive be used anywhere? No; each use must match one of the locations declared by its definition.
@deprecated@include@skiptype system directivesexecutable directivesFIELD_DEFINITIONENUM_VALUE