relay-compiler-language-scalajs
raw JSON → 0.41.0 verified Fri May 01 auth: no javascript
A Relay compiler language plugin that generates Scala.js bindings (js.native traits) instead of Flow types for GraphQL-driven Scala.js applications. Compatible with Relay 11.0.2, graphql ^15.4.0, and relay-runtime ^11.0.2. The plugin outputs compiled queries as Scala.js native traits, supports custom output via @scalajs directives (extends, useNulls), and uses artifactDirectory for flat package generation. Release cadence is irregular with minor version bumps for dependency updates. Differentiator: enables Relay for Scala.js/React.js integration, not maintained by the core Relay team.
Common errors
error Error: Cannot find module 'relay-compiler-language-scalajs' ↓
cause Missing npm install of the package
fix
Run: npm install --save-dev relay-compiler-language-scalajs
error Error: The language 'scalajs' is not supported. ↓
cause relay-compiler version mismatch or missing plugin
fix
Ensure relay-compiler@11.0.2 is installed and package is in node_modules.
error Error: No schema found at --schema path ↓
cause Invalid or missing GraphQL schema file
fix
Provide valid .graphql schema path via --schema.
error Error: Could not parse GraphQL file: unexpected directive ↓
cause Using @scalajs on unsupported GraphQL elements
fix
Only use @scalajs on fragments, fields, or inline fragments.
Warnings
gotcha Requires exact Relay version 11.0.2; other versions may break. ↓
fix Ensure relay-compiler version is pinned to 11.0.2.
gotcha Uses artifactDirectory flat layout; all generated files in one directory. ↓
fix Configure artifactDirectory to a dedicated output directory, not mixed with sources.
deprecated The @scalajs(extends) directive requires manual verification of parent class. ↓
fix Ensure the extended class exists in Scala.js scope.
gotcha graphql peer dependency must be ^15.4.0, not newer GraphQL versions. ↓
fix Use GraphQL 15.4.x or compatible.
Install
npm install relay-compiler-language-scalajs yarn add relay-compiler-language-scalajs pnpm add relay-compiler-language-scalajs Imports
- relay-compiler wrong
No direct JS import; used via CLIcorrectimport 'relay-compiler' (see docs) - @scalajs wrong
Not a JavaScript importcorrectUsed as GraphQL directive in .graphql files - relay-runtime wrong
Missing peer depcorrectnpm install relay-runtime
Quickstart
// 1. Install dependencies
npm install --save-dev relay-compiler@11.0.2 relay-compiler-language-scalajs graphql@^15.4.0
npm install relay-runtime@^11.0.2
// 2. Run relay-compiler with scalajs language
// ./node_modules/.bin/relay-compiler --language scalajs --src ./src --schema ./schema.graphql --artifactDirectory ./src/__generated__
// 3. Generated Scala.js file (example: src/__generated__/MyFragment.scala)
@js.native
trait MyFragment_data extends js.Object {
val id: String = js.native
val name: String | Null = js.native
}