---
title: "Understanding GraphQL Directives: Practical Use-Cases at Zalando"
description: "Zalando uses custom GraphQL directives to declare cross-cutting server behavior in the schema and to attach client metadata in queries."
url: "https://swe.quest/articles/understanding-graphql-directives-practical-use-cases-at-zalando-20796a0cce64c9f9"
canonical: "https://engineering.zalando.com/posts/2023/10/understanding-graphql-directives-practical-use-cases-zalando.html"
source: "Zalando Engineering"
published: "2023-10-18"
difficulty: "medium"
kind: "Case study"
reading_minutes: 12
tags: ["graphql","api-design","identity-auth","observability"]
---

# Understanding GraphQL Directives: Practical Use-Cases at Zalando

A post on [Zalando Engineering](https://swe.quest/sources/zalando.md), published 2023-10-18, 12 min read, Case study. Original: [https://engineering.zalando.com/posts/2023/10/understanding-graphql-directives-practical-use-cases-zalando.html](https://engineering.zalando.com/posts/2023/10/understanding-graphql-directives-practical-use-cases-zalando.html)

## Summary

Zalando uses custom GraphQL directives to declare cross-cutting server behavior in the schema and to attach client metadata in queries. Schema directives handle field-level authentication with ACR levels (@isAuthenticated), redacting sensitive arguments from logs and traces (@sensitive, backed by a keyword linter), restricting fields to dedicated HTTP endpoints for rate limiting and bot protection (@requireExplicitEndpoint), and gating persisted queries by schema stability (@draft, @allowedFor). They also control enum evolution for mobile clients (@final, @extensibleEnum) and generate entity ID boilerplate (@resolveEntityId). Query directives such as @component, @tracingTag and @omitErrorTag feed OpenTelemetry tracing and alerting, using a two-step AST extraction before execution and error-path matching after it.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [GraphQL](https://swe.quest/tags/graphql.md) (Backend & APIs)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)
- [Identity & auth](https://swe.quest/tags/identity-auth.md) (Security)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)

## Prerequisites

- GraphQL schemas and resolvers ([easy posts on GraphQL](https://swe.quest/tags/graphql.md?difficulty=easy))
- GraphQL query syntax ([easy posts on GraphQL](https://swe.quest/tags/graphql.md?difficulty=easy))

## Keywords

GraphQL, Zalando, graphql-tools, OpenTelemetry, persisted queries

## Related posts

- [GraphQL persisted queries and Schema stability](https://swe.quest/articles/graphql-persisted-queries-and-schema-stability-a96dada14e0377f0.md): Zalando Engineering · 2022-02-16 · Medium · 6 min read · GraphQL, API design, Schema migrations, Deployment
  Zalando disables arbitrary GraphQL queries in production and accepts only query IDs that were persisted at build time, where an ID is a hash of the normalized query.
- [How we use GraphQL at Europe's largest fashion e-commerce company](https://swe.quest/articles/how-we-use-graphql-at-europe-s-largest-fashion-e-commerce-company-98c53d6b8b858147.md): Zalando Engineering · 2021-03-03 · Easy · 6 min read · GraphQL, API design, Microservices, E-commerce, Resilience
  Zalando replaced a sprawl of per-page and per-platform Backend-for-Frontend services with a single unified GraphQL API owned via a shared monorepo across 12+ domain teams.
- [Optimize GraphQL Server with Lookaheads](https://swe.quest/articles/optimize-graphql-server-with-lookaheads-2ec291286b4baa0c.md): Zalando Engineering · 2021-03-17 · Medium · 12 min read · GraphQL, API design, Performance engineering, JavaScript
  Zalando's GraphQL server uses lookaheads on the resolver's info AST (fieldNodes and selection sets) to work out which sub-fields a query requests, then forwards them to backends that support partial responses via a fields parameter.
- [What's New in pg\_graphql v1.2](https://swe.quest/articles/what-s-new-in-pg-graphql-v1-2-8e0869fac360da26.md): Supabase · 2023-04-21 · Medium · 4 min read · GraphQL, PostgreSQL, API design
  pg\_graphql v1.1–1.2 now reflects views, materialized views and foreign tables into the GraphQL schema, with primary keys declared via a comment directive.
- [Modeling Errors in GraphQL](https://swe.quest/articles/modeling-errors-in-graphql-bde0367a83f4ea52.md): Zalando Engineering · 2021-04-12 · Medium · 10 min read · GraphQL, API design
  GraphQL's built-in errors array is untyped and undiscoverable, so Zalando splits failures into two categories based on who can act on them.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
