Package Exports
- relay-compiler
- relay-compiler/index.js
- relay-compiler/package.json
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (relay-compiler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Relay Compiler
Relay-Compiler is a code-generation toolkit for GraphQL. It contains the core functionalities of GraphQL code-gen, including file parsing, validation, syntax tree parsing and transformation.
Configuration in package.json
The simplest way to configure relay is to add a new relay section to your
package.json that contains the relay config.
At minimum, the relay config must specify where to find source files (i.e. files
containing graphql literals) and the GraphQL schema for the project.
// adding new section to package json
{
...
"scripts": {
"relay": "relay-compiler"
},
...
// relay configuration
"relay": {
"src": "./src",
"schema": "./src/schema/app_schema.graphql"
}
}Relay Compiler will automatically discover the config if:
- There is a
relay.config.json,relay.config.jsfile at the root of the project (i.e. in the same folder as thepackage.jsonfile). - The
package.jsonfile contains a"relay"key.
Additionally, this config file can be specified with the CLI argument --config
as follows:
npm run relay --config ./relay.jsonor with yarn
yarn relay --config ./relay.jsonPlease note, that if you pass configuration options via --cli arguments, you'll need to provide a separate configuration for the babel plugin.
File Finder
Relay compiler uses watchman to find
file sources, and "listen" to the file changes in the "watch" mode.
If watchman is not available, the compiler will
use glob to query the filesystem for files.
Configuration
Supported compiler configuration options
srcRoot directory of application code. [string] [required]schemaRelative path to the file with GraphQL SDL file. [string] [required]artifactDirectoryA specific directory to output all artifacts to. When enabling this the babel plugin needsartifactDirectoryto be set as well. [string]languageThe name of the language used for input files and generated artifacts. ["flow" | "typescript"] [default: "flow"]excludesDirectories to ignore undersrc. [array] [default: ["/node_modules/", "/mocks/", "/generated/"]]schemaExtensionsList of directories with schema extensions. [array]noFutureProofEnumsForflowonly. This option controls whether or not a catch-all entry is added to enum type definitions values that may be added in the future. Enabling this means you will have to update your application whenever the GraphQL server schema adds new enum values to prevent it from breaking. [boolean][default: false]customScalarsMappings from custom scalars in your schema to built-in GraphQL types, for type emission purposes. [object]eagerEsModulesThis option enables emitting ES modules artifacts. [boolean][default: false]persistConfigurlString, URL to send a POST request to to persist. This field is required inpersistConfig[string]paramsThe document will be in aPOSTparametertext. This map can contain additional parameters to send. [object]concurrencyThe maximum number concurrent requests that will be made tourl. Use a value greater than 0. [number]
codegenCommandCommand name that for relay compiler. [string]isDevVariableNameName of the global variable for dev mode (__DEV__). [string]jsModuleFormatFormatting style for generated files.commonjsorhaste. Default iscommonjs. [string]
CLI configuration
We also support a limited set of CLI arguments that should cover the most cases when you need to run the compiler.
--srcRelative path to the source code.--schemaRelative path to schema file.--artifactDirectoryCompiler output directory.--repersistRun the persister even if the query has not changed.--watchRun compiler inwatchmode. Requireswatchmanto be installed.--outputOutput format of the compiler. Supported options:debug|verbose|quiet|quietWithErrors. The default value isverbose.