⬡ GraphQL
Beginner
What are directives in GraphQL?
Answer
Directives provide a way to alter the behavior of a query or schema element. GraphQL ships with three built-in directives. @include(if: Boolean) conditionally includes a field if the argument is true. @skip(if: Boolean) conditionally skips a field if the argument is true. @deprecated(reason: String) marks a schema field as deprecated, which documentation tools surface as a warning. Example: { user { name email @include(if: $showEmail) } }. You can also define custom directives for cross-cutting concerns like authorization, caching hints, and input transformation.