Relay connects React views to GraphQL backends with declarative data requirements, colocated queries, and compiler-driven network batching.
Overview
Relay is a JavaScript framework for React applications that load and update server data through GraphQL. Components declare what fields they need via GraphQL fragments and queries placed beside the UI that consumes them, so data dependencies stay local and readable.
A build-time compiler aggregates fragment and query requirements across the app, deduplicates fields, and issues efficient GraphQL requests. Runtime APIs such as loadQuery, usePreloadedQuery, useFragment, and mutation helpers keep the store consistent, support optimistic updates, and limit re-renders when related records change.
The design assumes GraphQL conventions including connections for pagination, global object identification via the Node interface, and standard fragment composition. It integrates with Create React App and Next.js and targets both web React and React Native codebases.
Compared with imperative store access, Relay emphasizes declarative fetching, automatic cache updates after mutations, and optional Flow or TypeScript types generated per component.
Key features
- Colocated GraphQL queries and fragments
- Compiler-optimized query aggregation
- Declarative loadQuery data loading
- GraphQL mutation and optimistic updates
- Automatic store consistency on changes
- Connection-based list pagination
- Global object identification support
- Generated Flow or TypeScript types
Use cases
- Large-scale React data layers
- GraphQL-backed web applications
- React Native mobile clients
- Paginated list UIs
- Teams wanting typed component data