⬡ GraphQL Intermediate

What is Relay and how does it differ from Apollo Client?

Answer

Relay is Meta's production-grade GraphQL client for React, used at Facebook scale. Key differences from Apollo Client: (1) Co-location: Relay enforces that each component declares its own data requirements via fragments — mandatory, not optional. Components compose their fragments upward. (2) Compiler: Relay has a build-time compiler that validates fragments, generates optimized query artifacts, and creates TypeScript types — catches schema mismatches at build time. (3) Strict spec adherence: Relay requires the server to follow the Relay spec (global object IDs, cursor connections) — no flexibility. (4) Performance: Relay is optimized for massive data needs — incremental delivery, streaming, deferred fragments. (5) Learning curve: Relay is significantly more complex to set up and learn. (6) When to choose Relay: large-scale React apps with many components and complex data requirements. Apollo is easier to adopt and more flexible.