What are Directives in GraphQL?

Updated Apr 28, 2026

Short answer

Directives are instructions attached to fields or fragments that can alter the execution or structure of the query dynamically.

Deep explanation

The core GraphQL specification includes two default directives: @include(if: Boolean) to conditionally include a field, and @skip(if: Boolean) to conditionally skip a field. Custom directives can also be defined for the schema or query.

Real-world example

A UI toggle that reveals advanced details. The frontend passes $showAdvanced=true to fetch the extra data without writing a completely separate query.

Common mistakes

  • Using `@skip(if: false)` and expecting it to skip. The logic can be confusing
  • `@skip(if: true)` skips the field.

Follow-up questions

  • Can you define custom directives?

More GraphQL interview questions

View all →