graphql-minify 0.1.0

Minify GraphQL queries
Documentation
  • Coverage
  • 60%
    3 out of 5 items documented1 out of 1 items with examples
  • Size
  • Source code size: 31.62 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.77 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 16s Average build duration of successful builds.
  • all releases: 16s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • dan-lee/graphql-minify-rs
    17 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dan-lee

graphql-minify

This is a re-implementation of stripIgnoredCharacters from the GraphQL.js reference implementation in Rust. It uses Logos for tokenization.

All relevant tests are ported from the reference implementation and run against the Rust implementation.

Beware: It does not test for validity of the GraphQL document, its sole purpose is to minify the document as much as possible.

⚡️ Demo built with WASM

Strips characters that are not significant to the validity or execution of a GraphQL document:

  • UnicodeBOM
  • WhiteSpace
  • LineTerminator
  • Comment
  • Comma
  • BlockString indentation

Note: It is required to have a delimiter character between neighboring non-punctuator tokens and this function always uses single space as delimiter.

It is guaranteed that both input and output documents if parsed would result in the exact same AST except for nodes location.

Usage

use graphql_minify::minify;

fn main() {
  let minified = minify("query { user { id name } }");

  assert_eq!(minified.unwrap(), "query{user{id name}}");
}