{"library":"relay-compiler","title":"Relay Compiler","description":"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.","language":"javascript","status":"active","last_verified":"Fri May 01","install":{"commands":["npm install relay-compiler"],"cli":{"name":"relay-compiler","version":null}},"imports":["import { graphql } from 'relay-runtime'","import RelayCompiler from 'relay-compiler'","import type { RelayCompilerOptions } from 'relay-compiler'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"// Install: npm install relay-compiler relay-runtime\n// Generate schema.graphql first (e.g., from server introspection)\n\n// Run the compiler\nconst { execSync } = require('child_process');\nexecSync('npx relay-compiler --src ./src --schema ./schema.graphql --language typescript', { stdio: 'inherit' });\n\n// Use in code\nimport { graphql } from 'relay-runtime';\n\nconst query = graphql`\n  query MyQuery {\n    viewer {\n      name\n    }\n  }\n`;\n\nfetchGraphQL(query, {})\n  .then(data => console.log(data));\n\n// GraphQL fragments must be tagged with graphql and the file must match the naming convention\n// The compiler generates __generated__/MyQuery.graphql.ts\n","lang":"typescript","description":"Shows the basic setup: installing packages, running the compiler, and using a graphql-tagged query.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}