Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Zalando Engineering 12 min read Case study mediumAdept

Understanding GraphQL Directives: Practical Use-Cases at Zalando

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.

Related posts

  • GraphQL persisted queries and Schema stability

    Zalando Engineering mediumAdept

    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. Because every production query is known, the team can monitor and alert per query and tell which schema fields are unused and therefore safe to break. On top of this they add schema directives: @draft blocks a field from being persisted so it can be merged, deployed and changed freely. @component and @allowedFor restrict an experimental field to specific UI components, so a breaking change only touches those callers. Fields move from draft to restricted to stable, which lets the schema evolve without long-lived feature branches across microservices.

  • How we use GraphQL at Europe's largest fashion e-commerce company

    Zalando Engineering easyNovice

    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. The BFFs had duplicated effort, fragmented security and observability, and produced inconsistent data across web and app. The graph is built on Entities such as Product and Campaign and runs on their own GraphQL engine, graphql-jit, under a strict no-business-logic rule. Since 2018 it has grown to serve over 80% of web and 50% of app use cases, with adoption driven by documentation, training and schema consultation, and god-component risk handled through contribution principles, circuit breakers, timeouts, retries and per-platform bulkhead deployments.

  • Optimize GraphQL Server with Lookaheads

    Zalando Engineering mediumAdept

    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. Dependency maps translate schema fields to backend object paths for the request, and per-field transformer maps build the schema response from partial backend data without null-check sprawl. DataLoader batches product lookups across a query by merging ids and taking the union of requested backend fields, since most backends can't select different fields per id.

  • What's New in pg_graphql v1.2

    Supabase mediumAdept

    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. Simple views also support inserts and updates, which can keep older API shapes working while the underlying tables are migrated. Filtering gains `is: NULL/NOT_NULL` on every scalar filter plus `like`, `ilike` and `startsWith` on strings; `startsWith` is preferred because it can use plain B-tree indexes. The release also implements the spec's `@skip`/`@include` directives and lets users set table and column descriptions through comment directives, and requires Postgres 15.1.0.63 or later.

  • Modeling Errors in GraphQL

    Zalando Engineering mediumAdept

    GraphQL's built-in errors array is untyped and undiscoverable, so Zalando splits failures into two categories based on who can act on them. Errors stay in response.errors with an extensions.code (NOT_FOUND, NOT_AUTHORIZED, or no code for internal failures) and keep GraphQL's null-propagation semantics. Problems, named after RFC 7807, are schema types returned through Success/Problem result unions with translated messages. They are reserved mainly for mutation input validation, where only the customer can fix the issue. Using Problem types everywhere would bloat queries and front-end branching, so they should be used sparingly.

The quest for software engineering knowledge.

Look:
Layout: