The Relay Compiler is the build-time tool for the Relay GraphQL client, currently at stable version 20.1.1. It transforms GraphQL fragments and queries defined in JavaScript/TypeScript files into optimized runtime artifacts, including persisted query mappings. Released under a regular cadence with major updates every few months, it provides strict schema validation, type-safe fragment composition, and support for directives like @alias, @catch, and @preloadable. Key differentiators include deep integration with React via Suspense and load-as-you-render patterns, zero-runtime overhead from compiled operations, and strong typing via generated Flow or TypeScript definitions. Unlike Apollo's codegen, Relay Compiler enforces a global schema and prevents over-fetching by design through its colocation model.
npm install relay-compilerNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows the basic setup: installing packages, running the compiler, and using a graphql-tagged query.
Add @alias directive to all conditional fragments. Use --no-validate to temporarily opt out.
Remove config_id argument from @live directives. If needed, use a different identification mechanism.
Rename 'customScalars' to 'customScalarTypes' in relay.config.js.
Use import() or set type: 'module' in package.json. Alternatively, use dynamic import.
Monitor release notes for changes to @catch. Consider using @throwOnFieldError as stable alternative.
Provide the correct path to your schema.graphql file. Generate via: npx get-graphql-schema <ENDPOINT> -j | npx graphql-json-to-sdl > schema.graphql
Add @alias directive to the fragment spread. Example: ...MyFragment @alias(as: "myFragment")
Use default import: import RelayCompiler from 'relay-compiler'
Update relay-compiler to >=18.0.0. If stuck, use --experimental-modules flag in Node 14.