# babel-plugin-relay

> A Babel Plugin for use with Relay applications.

Latest version **21.0.1** (published 2026-05-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-relay
pnpm add babel-plugin-relay
yarn add babel-plugin-relay
bun add babel-plugin-relay
```

## Health

**Score 60/100 (C)** — status: active.

Positive: no vulnerabilities; has provenance; high maintenance score; popular repo.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 21.0.1 |
| Published | 2026-05-27 |
| First published | 2015-09-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 23.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 18958 |
| Maintainers | zpao, fb, yuzhi, josephsavona, relay-bot |
| Keywords | graphql, relay, babel, babel-plugin |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-relay
- Repository: https://github.com/facebook/relay
- Homepage: https://relay.dev
- Issues: https://github.com/facebook/relay/issues
- npm.io page: https://npm.io/package/babel-plugin-relay

## Dependencies (3)

- [graphql](https://npm.io/package/graphql.md) 15.3.0
- [cosmiconfig](https://npm.io/package/cosmiconfig.md) ^5.0.5
- [babel-plugin-macros](https://npm.io/package/babel-plugin-macros.md) ^2.0.0

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 21.0.1 (latest) — 2026-05-27
- 0.0.0-main-6e1ec733 (main) — 2026-09-25
- 13.0.0-rc.2 (dev) — 2021-12-29
- 0.0.0-main-b81643b1 — 2026-09-24
- 0.0.0-main-b8344d0d — 2026-09-24
- 0.0.0-main-8fb60eea — 2026-09-24
- 0.0.0-main-156c45b1 — 2026-09-24
- 0.0.0-main-9735eb4b — 2026-09-24
- 0.0.0-main-a4ee15bc — 2026-09-24
- 0.0.0-main-b21986c4 — 2026-09-23
- 0.0.0-main-af0bcbe0 — 2026-09-23
- 0.0.0-main-a7fa727b — 2026-09-22
- 0.0.0-main-f5b88420 — 2026-09-22
- 0.0.0-main-e3f5d71e — 2026-09-22
- 0.0.0-main-30f49981 — 2026-09-21
- … 4295 more at https://npm.io/package/babel-plugin-relay/versions

## README

## babel-plugin-relay

Relay requires a Babel plugin to convert GraphQL tags to runtime artifacts.

A _very_ simplified example of what this plugin is doing:

```js
// It converts this code
const fragment = graphql`
  fragment User_fragment on User {
    name
  }
`;

// To require generated ASTs for fragments and queries
const fragment = require('__generated__/User_fragment.graphql');
```

## Plugin Configuration

`babel-plugin-relay` will discover the config if:

- There is a `relay.config.json`, `relay.config.js` file at the root of the
  project (i.e. in the same folder as the `package.json` file).
- The `package.json` file contains a `"relay"` key.

### Supported configuration options for `babel-plugin-relay`

- `artifactDirectory` A specific directory to output all artifacts to. When
  enabling this the babel plugin needs `artifactDirectory` to be set as well.
  [string]
- `eagerEsModules` This option enables emitting ES modules artifacts.
  [boolean][default: false]
- `codegenCommand` The command to run to compile Relay files. [string]
- `isDevVariableName` Name of the global variable for dev mode (e.g. `__DEV__`).
  [string]
- `jsModuleFormat` Formatting style for generated files. `commonjs` or `haste`.
  Default is `commonjs`. [string]

[Configuration Instructions](https://relay.dev/docs/getting-started/installation-and-setup/#set-up-babel-plugin-relay)

---
_Source: https://npm.io/package/babel-plugin-relay · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
