# @rollup/plugin-graphql

> Convert .gql/.graphql files to ES6 modules

Latest version **3.0.0** (published 2026-05-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rollup/plugin-graphql
pnpm add @rollup/plugin-graphql
yarn add @rollup/plugin-graphql
bun add @rollup/plugin-graphql
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-05-29 |
| First published | 2020-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.0.0 |
| Dependencies | 2 |
| Unpacked size | 13.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 3759 |
| Author | rollup |
| Maintainers | shellscape, rich_harris, guybedford, lukastaegert |
| Keywords | rollup, plugin, graphql, apollo, import, modules, rollup-plugin |

## Links

- npm: https://www.npmjs.com/package/@rollup/plugin-graphql
- Repository: https://github.com/rollup/plugins
- Homepage: https://github.com/rollup/plugins/tree/master/packages/graphql#readme
- Issues: https://github.com/rollup/plugins/issues
- npm.io page: https://npm.io/package/@rollup/plugin-graphql

## Dependencies (2)

- [graphql-tag](https://npm.io/package/graphql-tag.md) ^2.12.6
- [@rollup/pluginutils](https://npm.io/package/@rollup/pluginutils.md) ^5.0.1

## 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

- 3.0.0 (latest) — 2026-05-29
- 2.0.5 — 2024-09-22
- 2.0.4 — 2023-10-05
- 2.0.3 — 2023-01-20
- 2.0.2 — 2022-10-27
- 2.0.1 — 2022-10-21
- 2.0.0 — 2022-10-09
- 1.1.0 — 2021-11-12
- 1.0.0 — 2020-10-27

## README

[npm]: https://img.shields.io/npm/v/@rollup/plugin-graphql
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-graphql
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-graphql
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-graphql

[![npm][npm]][npm-url]
[![size][size]][size-url]
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)

# @rollup/plugin-graphql

🍣 A Rollup plugin which Converts .gql/.graphql(s) files to ES6 modules.

## Requirements

This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v2.78.0+.

## Install

Using npm:

```console
npm install @rollup/plugin-graphql --save-dev
```

## Usage

Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:

```js
import graphql from '@rollup/plugin-graphql';

export default {
  input: 'src/index.js',
  output: {
    dir: 'output',
    format: 'cjs'
  },
  plugins: [graphql()]
};
```

Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).

With an accompanying file `src/index.js`, you can import GraphQL files or named queries/mutations:

```js
// src/index.js

// import a GraphQL Document from a GraphQL file,
import schema from './schema.graphql';

// or import named Query/Mutation
import { BatmanQuery, JokerMutation } from './schema.graphql';
```

#### Fragments

Thanks to [graphql-tag](https://github.com/apollographql/graphql-tag), fragments import is supported by using `#import "..."`.

Given the following file `heroFragment.graphql`:

```graphql
fragment HeroFragment on Hero {
  id
  name
}
```

You can import it like this:

```graphql
#import "./heroFragment.graphql"

query AllHeroes {
  heros {
    ...HeroFragment
  }
}
```

## Options

### `exclude`

Type: `String` | `Array[...String]`<br>
Default: `null`

A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored.

### `include`

Type: `String` | `Array[...String]`<br>
Default: `null`

A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.

## Meta

[CONTRIBUTING](/.github/CONTRIBUTING.md)

[LICENSE (MIT)](/LICENSE)

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