# @graphql-tools/documents

> Utilities for GraphQL documents.

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

## Install

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

## 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 | 1.0.2 |
| Published | 2026-09-07 |
| First published | 2023-01-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.0.0 |
| Dependencies | 1 |
| Unpacked size | 20.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 5430 |
| Maintainers | dotansimha, urigo, ardatan, enisdenjo, theguild-bot |

## Links

- npm: https://www.npmjs.com/package/@graphql-tools/documents
- 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/documents

## Dependencies (1)

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

## Recent versions

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

## README

# `@graphql-tools/documents`

Utilities for GraphQL documents.

## Install

```bash
npm install @graphql-tools/documents
```

## Contents

### Print GraphQL Documents

A stable way to print a GraphQL document. All executable/fragment variable definitions, fields are
printed in a stable way. Useful for stuff like persisted GraphQL operations.

#### Usage

```ts
import { parse } from 'graphql'
import { printExecutableGraphQLDocument } from '@graphql-tools/documents'

const inputDocument = parse(/* GraphQL */ `
  query A {
    ... on Query {
      a {
        ...B
        b
      }
    }
    ... on Query {
      a {
        ...B
        a
      }
    }
  }

  fragment B on Query {
    c
  }
`)
const outputStr = printExecutableGraphQLDocument(inputDocument)
console.assert(
  outputStr ===
    'fragment B on Query { c } query A { ... on Query { a { a ...B } } ... on Query { a { b ...B } } }',
  'Stuff is not equal.'
)
```

#### Rules

- Fragments are always printed before executable operations
- Executable operations are sorted alphabetically by name.
- Arguments (Directive, Fields) are sorted alphabetical
- Selections sets are sorted Field, FragmentSpread, InlineFragmentSpread (sorted based on
  TypeCondition, inner SelectionSet)

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