⬡ GraphQL Beginner

What are GraphQL directives?

Answer

Directives modify the behavior of fields or types at execution time. Built-in directives: @include(if: Boolean) — include a field only if the condition is true; @skip(if: Boolean) — skip a field if the condition is true; @deprecated(reason: "Use newField instead") — marks a field as deprecated in the schema; @specifiedBy(url: "...") — for custom scalar documentation. Usage: query GetUser($showEmail: Boolean!) { user(id: "1") { name email @include(if: $showEmail) } }. Servers can define custom directives for cross-cutting concerns like authentication (@auth), rate limiting (@rateLimit), caching (@cacheControl), or computed fields. Schema directives are applied at the SDL level; execution directives are used in queries.