@graphql-tools/optimize
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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

yarn add -D @graphql-tools/optimize

API

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

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:

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:

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

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

Versions

Current Tags

Version History

Package Sidebar

Install

npm i @graphql-tools/optimize

Weekly Downloads

3,894,095

Version

2.0.0

License

MIT

Unpacked Size

16.2 kB

Total Files

27

Last publish

Collaborators

  • dotansimha
  • urigo
  • ardatan