npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

swc-plugin-minify-graphql

v0.5.0

Published

GraphQL query and schema minimizer plugin for SWC

Readme

swc-plugin-minify-graphql

GraphQL query and schema minimizer plugin for SWC

Compatibility

Since WASM plugins are not fully backward compatible (see swc-project/swc#5060, Selecting the version - SWC), use the table below to select the correct plugin version:

| plugin version | used swc_core version | potentially compatible swc_core versions* | | -------------: | ----------------------: | :------------------------------------------- | | 0.5 | 55.0.2 | >=47 | | 0.4 | 46.0.3 | >=46 <47 | | 0.3 | 43.0.1 | >=40 <46 | | 0.2 | 10.6.1 | >=10 | | 0.1 | 1.0.2 | >=0.98.0 <10 |

* since this plugin uses a very small part of the API, the compatible version ranges are sometimes larger

[!NOTE] Version 0.5 and later use swc_ast_unknown, which should improve plugin compatibility (see this SWC's blog post and PR swc-project/swc#11100 for more info)

Usage

Install the package:

npm i swc-plugin-minify-graphql

and add it to your SWC config.

Basic

The plugin handles string literals and template literals marked with the GraphQL comment

const QUERY = /* GraphQL */ `
	query ($id: ID!) {
		image (id: $id) {
			...img
		}
	}

	fragment img on Image {
		id
		url
	}
`;

minifying them:

const QUERY = /* GraphQL */ `query($id:ID!){image(id:$id){...img}}fragment img on Image{id url}`;

Minification is supported not only for entire queries and schemas, but also for their individual parts (e.g., fragments):

const IMAGE_FIELDS = /* GraphQL */ `
	id
	url
`;
const IMAGE_FRAGMENT = /* GraphQL */ `
	fragment image on Image {
		id
		url
	}
`;

// becomes

const IMAGE_FIELDS = /* GraphQL */ `id url`;
const IMAGE_FRAGMENT = /* GraphQL */ `fragment image on Image{id url}`;

GraphQL comments are case-insensitive and can have any number of whitespace characters and asterisks at the beginning and end. /* graphql */, /* GraphQL */, /** GraphQL */ and even /* *** * gRaPhQl * *** */ will work.

Template literals with expressions

Expressions within template literals are also supported:

const IMAGE = /* GraphQL */ `
	id
	url
`;

const ENTITY = /* GraphQL */ `
	id
	image {
		${IMAGE}
		previewUrl
	}
`;

// becomes

const IMAGE = /* GraphQL */ `id url`;

const ENTITY = /* GraphQL */ `id image{${IMAGE} previewUrl}`;

But with a single exception: expressions cannot break GraphQL tokens. The following code is invalid:

const LONG = 'Long';

const FIELD = /* GraphQL */ `
	id
	some${LONG}FieldName
`;

// becomes

const FIELD = /* GraphQL */ `id some ${LONG} FieldName`;

// instead of

const FIELD = /* GraphQL */ `id some${LONG}FieldName`;
const FORMAT = 'long';

const IMAGE = /* GraphQL */ `
	id
	url (format: "${FORMAT}")
`;

// will throw error like this:

//   × failed to minify GraphQL
//    ╭─[input.js:4:1]
//  3 │
//  4 │ ╭─▶         const IMAGE = /* GraphQL */ `
//  5 │ │               id
//  6 │ ╰─▶             url (format: "${FORMAT}")
//    · ╰───                         ┬
//    · ╰───                         ╰── unknown token at 112
//  7 │             `;
//    ╰────

While the minified code may be correct in some cases, this usage is not intended and can be broken at any time.

gql tag support

gql/graphql tagged template literals are not currently supported, and there are no plans to add support. You can use other plugins like graphql-tag-swc-plugin that support minification.

Credits

License

Licensed under either of

  • The Unlicense (UNLICENSE or https://unlicense.org/UNLICENSE)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.


  1. on Codeberg - hikiko4ern/swc-plugin-minify-graphql (with releases)
  2. on Radicle - rad:z3Bv8pFGLdQ8jhW6dwq2x96tzvpiC (code only)