Skip to content

Instantly share code, notes, and snippets.

View narennaik's full-sized avatar

Naren Naik narennaik

View GitHub Profile
@narennaik
narennaik / compressGraphqlDocument.js
Created March 15, 2019 11:57 — forked from rybon/compressGraphqlDocument.js
Remove unnecessary whitespace from a GraphQL query / mutation / subscription
const compressGraphqlDocument = graphqlDocument =>
graphqlDocument
.replace(/#.*\n/g, '')
.replace(/[\s|,]*\n+[\s|,]*/g, ' ')
.replace(/:\s/g, ':')
.replace(/,\s/g, ',')
.replace(/\)\s\{/g, '){')
.replace(/\}\s/g, '}')
.replace(/\{\s/g, '{')
.replace(/\s\}/g, '}')