# @graphql-tools/optimize

> A set of utils for faster development of GraphQL tools

Latest version **2.0.1** (published 2026-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @graphql-tools/optimize
pnpm add @graphql-tools/optimize
yarn add @graphql-tools/optimize
bun add @graphql-tools/optimize
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2026-09-07 |
| First published | 2020-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.0.0 |
| Dependencies | 1 |
| Unpacked size | 16.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 5431 |
| Maintainers | dotansimha, urigo, ardatan, enisdenjo, theguild-bot |

## Links

- npm: https://www.npmjs.com/package/@graphql-tools/optimize
- Repository: https://github.com/ardatan/graphql-tools
- Homepage: https://github.com/ardatan/graphql-tools#readme
- Issues: https://github.com/ardatan/graphql-tools/issues
- npm.io page: https://npm.io/package/@graphql-tools/optimize

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.4.0

## Recent versions

- 2.0.1 (latest) — 2026-09-07
- 2.0.1-alpha-20260908131015-b2dfc3e4ee71c6ef42759b0256a502f523eabc05 (alpha) — 2026-09-08
- 2.0.1-rc-20260907155438-70f93ec122ac510059d67d2c95fa983767d228e4 (rc) — 2026-09-07
- 2.0.1-alpha-20260907152509-b7cc349bd7a5caa3d87fc65e40a8263f158fccb5 — 2026-09-07
- 2.0.1-alpha-20260907125251-688d2698f7b2dc5e416809134e029131bdc4ae18 — 2026-09-07
- 2.0.1-alpha-20260907124139-5ba4f97292a9c4bb81838696a2c41c5e68d242a9 — 2026-09-07
- 2.0.1-alpha-20260907123756-5ba4f97292a9c4bb81838696a2c41c5e68d242a9 — 2026-09-07
- 2.0.1-alpha-20260907123755-1197358972f8c350e3f88b359cff7d05b98cba70 — 2026-09-07
- 2.0.1-alpha-20260907122737-b1d6651183ddba10b8e9273f8a954e04e9e7c60e — 2026-09-07
- 2.0.1-alpha-20260907122548-6acc8a0e4697da092d5632e22db2c794fa7a6d62 — 2026-09-07
- 2.0.1-alpha-20260907122329-b6c58cd28d24d206e02cecdc28db1c6c2063d6d0 — 2026-09-07
- 2.0.1-alpha-20260907121829-a83ee80d70869afc901c89720c750aaaabae7a7e — 2026-09-07
- 2.0.1-alpha-20260907121647-5cfb2ae48eb48e97a9ab71450cd44ae52f71f342 — 2026-09-07
- 2.0.1-alpha-20260907015238-9ebe5a42014dfa0b23381e932c70f68985f9cf60 — 2026-09-07
- 2.0.1-rc-20260906080057-0c56431a8869215e2b0f271defcf32e6004f422d — 2026-09-06
- … 145 more at https://npm.io/package/@graphql-tools/optimize/versions

## README

# GraphQL Tools: `DocumentNode` Optimizer

This package is intended to allow developers to optimize `DocumentNode` objects created by `graphql`
library.

It's built as a set of small optimizers you can compose to get the most out of your GraphQL setup.

The goal of this package is mostly around making optimizations for the way the data is stored in
`DocumentNode`, and not to the essence of the `DocumentNode`.

## Getting Started

    npm install -D @graphql-tools/optimize

## API

To get started with this tool, import it and run it over your `DocumentNode`.

```ts
import { optimizeDocumentNode } from '@graphql-tools/optimize';

const myDocument: DocumentNode = { ... }
const optimizedDocument = optimizeDocumentNode(myDocument);
```

### Customizing Optimizers

By default, we apply all optimizers available in this repo over your document. It shouldn't effect
any runtime since we just remove dead or unused areas.

You can modify the list of optimizers this way:

```ts
import { optimizeDocumentNode, removeDescriptions } from '@graphql-tools/optimize';

const myDocument: DocumentNode = { ... }
const optimizedDocument = optimizeDocumentNode(myDocument, [removeDescriptions]);
```

### Writing your own optimizer

You can create your own optimizer to manipulate `DocumentNode`, the API signature is pretty simple:

```ts
export type DocumentOptimizer = (input: DocumentNode) => DocumentNode
```

Take a look at [./optimizers](this directory for inspiration and implementation reference).

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