A high-performance GraphQL compilation tool built in Rust for building Relay applications with optimized queries and type generation.
—
The Relay Compiler command-line interface provides powerful tools for compiling GraphQL files, running in watch mode, validating changes, and managing LSP integration.
# Install globally
npm install -g relay-compiler
# Install locally
npm install relay-compilerThe relay-compiler package automatically detects your platform and uses the appropriate binary:
const relayBinary = require('relay-compiler');
console.log(relayBinary); // Returns path to platform-specific binary or nullSupported Platforms:
macos-x64/relaymacos-arm64/relaylinux-x64/relaylinux-arm64/relaywin-x64/relay.exeThe default command compiles Relay files and writes generated files.
{ .api }
relay-compiler [OPTIONS]{ .api }
--watch, -w # Compile and watch for changes
--project, -p <PROJECT> # Compile specific project (repeatable)
--config <PATH> # Use specific config file
--src <PATH> # Path to source directory
--schema <PATH> # Path to schema file
--artifact-directory <PATH> # Output directory for artifacts
--repersist # Force re-persistence of queries
--output <KIND> # Verbosity level
--validate # Check for changes without writing{ .api }
type OutputKind = "debug" | "quiet" | "quiet-with-errors" | "verbose";# Basic compilation
relay-compiler --src ./src --schema ./schema.graphql
# Watch mode for development
relay-compiler --watch --src ./src --schema ./schema.graphql
# Compile specific projects
relay-compiler --project web --project mobile
# Validation mode (no file writes)
relay-compiler --validate --src ./src --schema ./schema.graphql
# Custom artifact directory
relay-compiler --src ./src --schema ./schema.graphql --artifact-directory ./generated
# Verbose output with re-persistence
relay-compiler --output verbose --repersist --src ./src --schema ./schema.graphqlRun the LSP server for IDE integration.
{ .api }
relay-compiler lsp [OPTIONS]{ .api }
--config <PATH> # Config file path
--output <KIND> # Verbosity level (default: quiet-with-errors)
--locate-command <SCRIPT> # Script for GraphQL entity location lookup# Start LSP server
relay-compiler lsp
# Start with custom config
relay-compiler lsp --config ./relay.config.json
# Start with entity location script
relay-compiler lsp --locate-command "./scripts/find-graphql-entity.sh"
# Start with debug output
relay-compiler lsp --output debugPrint the JSON schema for Relay compiler configuration.
{ .api }
relay-compiler config-json-schemaThis outputs the complete JSON schema definition for configuration validation and IDE support.
# Output schema to file
relay-compiler config-json-schema > relay-config.schema.jsonApply automated code transformations with safety controls.
{ .api }
relay-compiler codemod <CODEMOD> [OPTIONS]{ .api }
relay-compiler codemod mark-dangerous-conditional-fragment-spreads [OPTIONS]Options:
--rollout-percentage, -r <PERCENT>: Percentage or range (e.g., "50" or "20-30")--project, -p <PROJECT>: Target specific projects--config <PATH>: Use specific config fileUsage Examples:
# Apply to 50% of files
relay-compiler codemod mark-dangerous-conditional-fragment-spreads --rollout-percentage 50
# Apply to percentage range
relay-compiler codemod mark-dangerous-conditional-fragment-spreads -r 20-30
# Apply to specific project
relay-compiler codemod mark-dangerous-conditional-fragment-spreads --project web{ .api }
relay-compiler codemod remove-unnecessary-required-directives [OPTIONS]Options:
--project, -p <PROJECT>: Target specific projects--config <PATH>: Use specific config fileUsage Examples:
# Apply to all projects
relay-compiler codemod remove-unnecessary-required-directives
# Apply to specific project
relay-compiler codemod remove-unnecessary-required-directives --project mobileWhen no --config option is provided, the compiler searches for configuration in this order:
relay.config.json in current directoryrelay.config.js in current directoryrelay key in package.jsonThe CLI provides detailed error messages for common issues:
{ .api }
interface CLIErrors {
ProjectFilterError: string; // Invalid project selection
ConfigError: string; // Configuration validation failures
CompilerError: string; // Compilation failures
CodemodError: string; // Codemod application failures
}Common Error Scenarios:
{ .api }
FORCE_NO_WATCHMAN=1 # Disable Watchman integration, use filesystem watching{ .api }
type ExitCodes = {
0: "Success";
1: "General error";
2: "Validation failures (--validate mode)";
}Install with Tessl CLI
npx tessl i tessl/npm-relay-compiler